109 DP("ConnectHttpSessionL END"); |
112 DP("ConnectHttpSessionL END"); |
110 } |
113 } |
111 |
114 |
112 void CHttpClient::ConnectCompleteL(TInt aErrorCode) |
115 void CHttpClient::ConnectCompleteL(TInt aErrorCode) |
113 { |
116 { |
|
117 DP1("CHttpClient::ConnectCompleteL BEGIN, aErrorCode=%d", aErrorCode); |
|
118 DP1(" iWaitingForGet=%d", iWaitingForGet); |
114 if(iWaitingForGet) |
119 if(iWaitingForGet) |
115 { |
120 { |
116 iWaitingForGet = EFalse; |
121 iWaitingForGet = EFalse; |
117 if( aErrorCode == KErrNone) |
122 if( aErrorCode == KErrNone) |
118 { |
123 { |
|
124 TRAP_IGNORE(iSession.OpenL()); |
|
125 DP(" one"); |
119 RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); |
126 RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); |
|
127 DP(" one point five"); |
120 RStringPool pool = iSession.StringPool(); |
128 RStringPool pool = iSession.StringPool(); |
121 // Attach to socket server |
129 // Attach to socket server |
|
130 DP(" two"); |
122 connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable()), THTTPHdrVal(iPodcastModel.ConnectionEngine().SockServ().Handle())); |
131 connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable()), THTTPHdrVal(iPodcastModel.ConnectionEngine().SockServ().Handle())); |
123 // Attach to connection |
132 // Attach to connection |
|
133 DP(" three"); |
124 TInt connPtr = REINTERPRET_CAST(TInt, &iPodcastModel.ConnectionEngine().Connection()); |
134 TInt connPtr = REINTERPRET_CAST(TInt, &iPodcastModel.ConnectionEngine().Connection()); |
125 connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal(connPtr)); |
135 connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal(connPtr)); |
126 |
136 DP(" four"); |
127 |
137 |
128 iPodcastModel.SetProxyUsageIfNeededL(iSession); |
138 iPodcastModel.SetProxyUsageIfNeededL(iSession); |
129 DoGetAfterConnectL(); |
139 DoGetAfterConnectL(); |
|
140 //iWaitingForGet = EFalse; // set to true by DoGetAfterConnectL |
130 } |
141 } |
131 else |
142 else |
132 { |
143 { |
133 ClientRequestCompleteL(KErrCouldNotConnect); |
144 ClientRequestCompleteL(KErrCouldNotConnect); |
134 iSession.Close(); |
145 iSession.Close(); |
135 } |
146 } |
136 } |
147 } |
|
148 DP("CHttpClient::ConnectCompleteL END"); |
137 } |
149 } |
138 |
150 |
139 void CHttpClient::Disconnected() |
151 void CHttpClient::Disconnected() |
140 { |
152 { |
141 iIsActive = EFalse; |
153 iIsActive = EFalse; |
142 iSession.Close(); |
154 iSession.Close(); |
143 } |
155 } |
144 |
156 |
145 void CHttpClient::DoGetAfterConnectL() |
157 void CHttpClient::DoGetAfterConnectL() |
146 { |
158 { |
|
159 DP("CHttpClient::DoGetAfterConnectL BEGIN"); |
147 // since nothing should be downloading now. Delete the handler |
160 // since nothing should be downloading now. Delete the handler |
148 if (iHandler) |
161 if (iHandler) |
149 { |
162 { |
150 delete iHandler; |
163 delete iHandler; |
151 iHandler = NULL; |
164 iHandler = NULL; |
156 |
169 |
157 TEntry entry; |
170 TEntry entry; |
158 TBuf8<KTempBufferSize> rangeText; |
171 TBuf8<KTempBufferSize> rangeText; |
159 |
172 |
160 if (iResumeEnabled && iPodcastModel.FsSession().Entry(iCurrentFileName, entry) == KErrNone) { |
173 if (iResumeEnabled && iPodcastModel.FsSession().Entry(iCurrentFileName, entry) == KErrNone) { |
161 DP1("Found file, with size=%d", entry.iSize); |
174 DP1(" Found file, with size=%d", entry.iSize); |
162 // file exists, so we should probably resume |
175 // file exists, so we should probably resume |
163 rangeText.Format(_L8("bytes=%d-"), (entry.iSize-KByteOverlap > 0 ? entry.iSize-KByteOverlap : 0)); |
176 rangeText.Format(_L8("bytes=%d-"), (entry.iSize-KByteOverlap > 0 ? entry.iSize-KByteOverlap : 0)); |
164 iHandler->SetSaveFileName(iCurrentFileName, ETrue); |
177 iHandler->SetSaveFileName(iCurrentFileName, ETrue); |
165 } else { |
178 } else { |
166 // otherwise just make sure the directory exists |
179 // otherwise just make sure the directory exists |
177 // Add headers appropriate to all methods |
190 // Add headers appropriate to all methods |
178 SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent); |
191 SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent); |
179 SetHeaderL(hdr, HTTP::EAccept, KAccept); |
192 SetHeaderL(hdr, HTTP::EAccept, KAccept); |
180 TBuf<KTempBufferSize> range16; |
193 TBuf<KTempBufferSize> range16; |
181 range16.Copy(rangeText); |
194 range16.Copy(rangeText); |
182 DP1("range text: %S", &range16); |
195 DP1(" range text: %S", &range16); |
183 if (rangeText.Length() > 0) { |
196 if (rangeText.Length() > 0) { |
184 SetHeaderL(hdr, HTTP::ERange, rangeText); |
197 SetHeaderL(hdr, HTTP::ERange, rangeText); |
185 } |
198 } |
186 iTransactionCount++; |
199 iTransactionCount++; |
187 // submit the transaction |
200 // submit the transaction |
188 iTrans.SubmitL(); |
201 iTrans.SubmitL(); |
189 iIsActive = ETrue; |
202 iIsActive = ETrue; |
190 DP("CHttpClient::Get END"); |
203 DP("CHttpClient::DoGetAfterConnectL END"); |
191 } |
204 } |
192 |
205 |
193 TBool CHttpClient::GetL(const TDesC& aUrl, const TDesC& aFileName, TBool aSilent) { |
206 TBool CHttpClient::GetL(const TDesC& aUrl, const TDesC& aFileName, TBool aSilent) { |
194 DP("CHttpClient::Get START"); |
207 DP("CHttpClient::Get START"); |
195 |
208 |
213 return EFalse; |
226 return EFalse; |
214 } |
227 } |
215 |
228 |
216 iSilentGet = aSilent; |
229 iSilentGet = aSilent; |
217 iCurrentFileName.Copy(aFileName); |
230 iCurrentFileName.Copy(aFileName); |
218 iWaitingForGet = ETrue; |
|
219 |
231 |
220 if (iTransactionCount == 0) |
232 if (iTransactionCount == 0) |
221 { |
233 { |
222 DP("CHttpClient::GetL\t*** Opening HTTP session ***"); |
234 DP("CHttpClient::GetL\t*** Opening HTTP session ***"); |
223 iSession.Close(); |
235 iSession.Close(); |
224 iSession.OpenL(); |
236 iSession.OpenL(); |
|
237 iWaitingForGet = ETrue; |
225 ConnectHttpSessionL(); |
238 ConnectHttpSessionL(); |
226 } |
239 } |
227 else |
240 else |
228 { |
241 { |
|
242 iWaitingForGet = EFalse; |
229 DoGetAfterConnectL(); |
243 DoGetAfterConnectL(); |
230 } |
244 } |
231 return ETrue; |
245 return ETrue; |
232 } |
246 } |
233 |
247 |
255 TRAP_IGNORE(iObserver.CompleteL(this, KErrDisconnected)); |
269 TRAP_IGNORE(iObserver.CompleteL(this, KErrDisconnected)); |
256 |
270 |
257 } |
271 } |
258 |
272 |
259 void CHttpClient::ClientRequestCompleteL(TInt aErrorCode) { |
273 void CHttpClient::ClientRequestCompleteL(TInt aErrorCode) { |
|
274 DP1("CHttpClient::ClientRequestCompleteL, aErrorCode=%d", aErrorCode); |
260 iIsActive = EFalse; |
275 iIsActive = EFalse; |
261 iObserver.CompleteL(this, aErrorCode); |
276 iObserver.CompleteL(this, aErrorCode); |
262 DP("CHttpClient::ClientRequestCompleteL"); |
277 DP1(" iTransactionCount=%d", iTransactionCount); |
263 if(iTransactionCount>0) |
278 if(iTransactionCount>0) |
264 { |
279 { |
265 iTransactionCount--; |
280 iTransactionCount--; |
266 |
281 |
267 if(iTransactionCount == 0) |
282 if(iTransactionCount == 0) |