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