| author | Sebastian Brannstrom <sebastianb@symbian.org> | 
| Sat, 13 Nov 2010 22:05:25 +0000 | |
| branch | newlist | 
| changeset 347 | b8d687bb7ca1 | 
| parent 336 | 3d6c1417e8bd | 
| permissions | -rw-r--r-- | 
| 2 | 1 | /* | 
| 2 | * Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB | |
| 3 | * | |
| 4 | * All rights reserved. | |
| 5 | * This component and the accompanying materials are made available | |
| 6 | * under the terms of the License "Eclipse Public License v1.0" | |
| 7 | * which accompanies this distribution, and is available | |
| 8 | * at the URL "http://www.eclipse.org/legal/epl-v10.html". | |
| 9 | * | |
| 10 | * Initial Contributors: | |
| 11 | * EmbedDev AB - initial contribution. | |
| 12 | * | |
| 13 | * Contributors: | |
| 14 | * | |
| 15 | * Description: | |
| 16 | * | |
| 17 | */ | |
| 18 | ||
| 19 | // HttpEventHandler.cpp | |
| 20 | #include <e32debug.h> | |
| 21 | #include <httperr.h> | |
| 245 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 22 | #include <sysutil.h> | 
| 2 | 23 | #include "HttpEventHandler.h" | 
| 24 | #include "bautils.h" | |
| 25 | #include "Httpclient.h" | |
| 336 
3d6c1417e8bd
Merged all the later Symbian3 updates into Symbian1 branch; new SIS v. 1.00.32
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
284diff
changeset | 26 | #include "Podcatcher.pan" | 
| 2 | 27 | |
| 245 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 28 | const TInt64 KMinDiskSpace = 1024 * 1024; // at least 1 MB must remain | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 29 | |
| 2 | 30 | void CHttpEventHandler::ConstructL() | 
| 31 | 	{
 | |
| 32 | //iVerbose = ETrue; | |
| 33 | } | |
| 34 | ||
| 35 | ||
| 36 | CHttpEventHandler::CHttpEventHandler(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs): | |
| 37 | iFileServ(aFs), iHttpClient(aClient), iCallbacks(aCallbacks) | |
| 38 | 	{
 | |
| 39 | } | |
| 40 | ||
| 41 | ||
| 42 | CHttpEventHandler::~CHttpEventHandler() | |
| 43 | 	{	
 | |
| 44 | } | |
| 45 | ||
| 46 | ||
| 47 | CHttpEventHandler* CHttpEventHandler::NewLC(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs) | |
| 48 | 	{
 | |
| 49 | CHttpEventHandler* me = new(ELeave)CHttpEventHandler(aClient, aCallbacks, aFs); | |
| 50 | CleanupStack::PushL(me); | |
| 51 | me->ConstructL(); | |
| 52 | return me; | |
| 53 | } | |
| 54 | ||
| 55 | ||
| 56 | CHttpEventHandler* CHttpEventHandler::NewL(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs) | |
| 57 | 	{
 | |
| 58 | CHttpEventHandler* me = NewLC(aClient, aCallbacks, aFs); | |
| 59 | CleanupStack::Pop(me); | |
| 60 | return me; | |
| 61 | } | |
| 62 | ||
| 63 | void CHttpEventHandler::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) | |
| 64 | 	{
 | |
| 336 
3d6c1417e8bd
Merged all the later Symbian3 updates into Symbian1 branch; new SIS v. 1.00.32
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
284diff
changeset | 65 | 	//DP1("CHttpEventHandler::MHFRunL, aEvent.iStatus=%d", aEvent.iStatus);
 | 
| 2 | 66 | switch (aEvent.iStatus) | 
| 67 | 		{
 | |
| 68 | case THTTPEvent::EGotResponseHeaders: | |
| 69 | 			{
 | |
| 70 | // HTTP response headers have been received. We can determine now if there is | |
| 71 | // going to be a response body to save. | |
| 72 | RHTTPResponse resp = aTransaction.Response(); | |
| 73 | iLastStatusCode = resp.StatusCode(); | |
| 60 | 74 | 			DP1("Status: %d", iLastStatusCode);
 | 
| 2 | 75 | |
| 76 | // Dump the headers if we're being verbose | |
| 77 | //DumpRespHeadersL(aTransaction); | |
| 78 | ||
| 79 | if (resp.HasBody() && (iLastStatusCode >= 200) && (iLastStatusCode < 300) && (iLastStatusCode != 204)) | |
| 80 | 				{
 | |
| 81 | TInt dataSize = resp.Body()->OverallDataSize(); | |
| 82 | 				if (dataSize >= 0) {
 | |
| 83 | 					DP1("Response body size is %d", dataSize);
 | |
| 84 | iBytesTotal = dataSize; | |
| 85 | 				} else {
 | |
| 86 | 					DP("Response body size is unknown");
 | |
| 87 | iBytesTotal = -1; | |
| 88 | } | |
| 89 | iCallbacks.DownloadInfo(iHttpClient, dataSize); | |
| 90 | ||
| 91 | } | |
| 92 | ||
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 93 | 			DP1("iFileOpen=%d", iFileOpen);
 | 
| 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 94 | if (!iFileOpen) | 
| 2 | 95 | 				{
 | 
| 96 | iFileServ.Parse(iFileName, iParsedFileName); | |
| 97 | TInt valid = iFileServ.IsValidName(iFileName); | |
| 60 | 98 | |
| 2 | 99 | if (!valid) | 
| 100 | 					{
 | |
| 101 | 					DP("The specified filename is not valid!.");
 | |
| 60 | 102 | iHttpClient->ClientRequestCompleteL(KErrBadName); | 
| 2 | 103 | } | 
| 104 | else | |
| 105 | 					{
 | |
| 106 | 					if (iContinue) {
 | |
| 107 | TInt err = iRespBodyFile.Open(iFileServ, iParsedFileName.FullName(),EFileWrite); | |
| 108 | if (err) | |
| 109 | 							{
 | |
| 164 
000f9fc147b2
Catch up with default branch; New v 27 SIS
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
90diff
changeset | 110 | 							DP2("There was an error=%d opening file '%S'", err, &iParsedFileName.FullName());
 | 
| 60 | 111 | iHttpClient->ClientRequestCompleteL(KErrInUse); | 
| 2 | 112 | User::Leave(err); | 
| 60 | 113 | } | 
| 114 | else | |
| 115 | 							{
 | |
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 116 | iFileOpen = ETrue; | 
| 2 | 117 | int pos = -KByteOverlap; | 
| 60 | 118 | if((err=iRespBodyFile.Seek(ESeekEnd, pos)) != KErrNone) | 
| 119 | 								{
 | |
| 2 | 120 | 								DP("Failed to set position!");
 | 
| 60 | 121 | iHttpClient->ClientRequestCompleteL(KErrWrite); | 
| 2 | 122 | User::Leave(err); | 
| 60 | 123 | } | 
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 124 | iBytesDownloaded = (pos > 0) ? pos : 0; | 
| 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 125 | iBytesTotal += iBytesDownloaded; | 
| 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 126 | 							DP1("Total bytes is now %u", iBytesTotal);
 | 
| 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 127 | 							DP1("Seeking end: %d", pos);
 | 
| 2 | 128 | } | 
| 60 | 129 | } | 
| 130 | else | |
| 131 | 						{
 | |
| 2 | 132 | TInt err = iRespBodyFile.Replace(iFileServ, | 
| 133 | iParsedFileName.FullName(), | |
| 134 | EFileWrite); | |
| 135 | if (err) | |
| 136 | 							{
 | |
| 137 | 							DP("There was an error replacing file");
 | |
| 138 | User::Leave(err); | |
| 139 | } | |
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 140 | else | 
| 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 141 | 							{
 | 
| 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 142 | iFileOpen = ETrue; | 
| 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 143 | } | 
| 2 | 144 | } | 
| 145 | } | |
| 146 | } | |
| 147 | } break; | |
| 148 | case THTTPEvent::EGotResponseBodyData: | |
| 149 | 			{
 | |
| 150 | // Get the body data supplier | |
| 151 | iRespBody = aTransaction.Response().Body(); | |
| 152 | ||
| 153 | // Some (more) body data has been received (in the HTTP response) | |
| 154 | //DumpRespBody(aTransaction); | |
| 155 | 			//DP1("Saving: %d", iSavingResponseBody);
 | |
| 245 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 156 | |
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 157 | // check if we have enough disk space | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 158 | if (iDriveNo != -1 && SysUtil::DiskSpaceBelowCriticalLevelL( &iFileServ, KMinDiskSpace, iDriveNo )) | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 159 | 				{
 | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 160 | TInt error = KErrDiskFull; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 161 | iFileOpen = EFalse; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 162 | iRespBodyFile.Close(); | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 163 | iCallbacks.FileError(error); | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 164 | iHttpClient->ClientRequestCompleteL(error); | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 165 | return; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 166 | } | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 167 | |
| 2 | 168 | // Append to the output file if we're saving responses | 
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 169 | if (iFileOpen) | 
| 2 | 170 | 				{
 | 
| 171 | TPtrC8 bodyData; | |
| 172 | iRespBody->GetNextDataPart(bodyData); | |
| 173 | iBytesDownloaded += bodyData.Length(); | |
| 174 | TInt error = iRespBodyFile.Write(bodyData); | |
| 60 | 175 | |
| 2 | 176 | // on writing error we close connection | 
| 177 | 				if (error != KErrNone) {
 | |
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 178 | iFileOpen = EFalse; | 
| 60 | 179 | iRespBodyFile.Close(); | 
| 2 | 180 | iCallbacks.FileError(error); | 
| 181 | iHttpClient->ClientRequestCompleteL(error); | |
| 182 | return; | |
| 183 | } | |
| 184 | ||
| 185 | 				if (!iSilent) {
 | |
| 186 | iCallbacks.Progress(iHttpClient, iBytesDownloaded, iBytesTotal); | |
| 187 | } | |
| 188 | } | |
| 189 | ||
| 190 | // Done with that bit of body data | |
| 191 | iRespBody->ReleaseData(); | |
| 192 | } break; | |
| 193 | case THTTPEvent::EResponseComplete: | |
| 194 | 			{
 | |
| 195 | // The transaction's response is complete | |
| 196 | 			DP("Transaction Complete");
 | |
| 197 | 			DP("Closing file");
 | |
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 198 | iFileOpen = EFalse; | 
| 2 | 199 | iRespBodyFile.Close(); | 
| 200 | } break; | |
| 201 | case THTTPEvent::ESucceeded: | |
| 202 | 			{
 | |
| 203 | 			DP("Transaction Successful");
 | |
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 204 | iFileOpen = EFalse; | 
| 80 
ea2321db6cb6
Forgot to close file handle on failed download. Fixed now. Also fix for SQLite static library.
 teknolog parents: 
60diff
changeset | 205 | iRespBodyFile.Close(); | 
| 2 | 206 | aTransaction.Close(); | 
| 207 | iHttpClient->ClientRequestCompleteL(KErrNone); | |
| 208 | } break; | |
| 209 | case THTTPEvent::EFailed: | |
| 210 | 			{
 | |
| 211 | 			DP("Transaction Failed");
 | |
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 212 | iFileOpen = EFalse; | 
| 80 
ea2321db6cb6
Forgot to close file handle on failed download. Fixed now. Also fix for SQLite static library.
 teknolog parents: 
60diff
changeset | 213 | iRespBodyFile.Close(); | 
| 2 | 214 | aTransaction.Close(); | 
| 215 | ||
| 216 | if(iLastStatusCode == HTTPStatus::EOk || iLastStatusCode == HTTPStatus::ECreated || iLastStatusCode == HTTPStatus::EAccepted) | |
| 217 | 				{
 | |
| 218 | iLastStatusCode = KErrNone; | |
| 219 | } | |
| 220 | ||
| 221 | iHttpClient->ClientRequestCompleteL(iLastStatusCode); | |
| 222 | } break; | |
| 223 | case THTTPEvent::ERedirectedPermanently: | |
| 224 | 			{
 | |
| 225 | 			DP("Permanent Redirection");
 | |
| 226 | } break; | |
| 227 | case THTTPEvent::ERedirectedTemporarily: | |
| 228 | 			{
 | |
| 229 | 			DP("Temporary Redirection");
 | |
| 230 | } break; | |
| 231 | default: | |
| 232 | 			{
 | |
| 233 | 			DP1("<unrecognised event: %d>", aEvent.iStatus);
 | |
| 234 | // close off the transaction if it's an error | |
| 164 
000f9fc147b2
Catch up with default branch; New v 27 SIS
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
90diff
changeset | 235 | if (aEvent.iStatus < 0) | 
| 2 | 236 | 				{
 | 
| 167 
4bfc2fcec5f6
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
164diff
changeset | 237 | iFileOpen = EFalse; | 
| 80 
ea2321db6cb6
Forgot to close file handle on failed download. Fixed now. Also fix for SQLite static library.
 teknolog parents: 
60diff
changeset | 238 | iRespBodyFile.Close(); | 
| 2 | 239 | aTransaction.Close(); | 
| 240 | iHttpClient->ClientRequestCompleteL(aEvent.iStatus); | |
| 241 | } | |
| 242 | } break; | |
| 243 | } | |
| 244 | } | |
| 245 | ||
| 60 | 246 | TInt CHttpEventHandler::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/) | 
| 2 | 247 | 	{
 | 
| 248 | 	DP1("MHFRunError fired with error code %d", aError);
 | |
| 60 | 249 | aTransaction.Close(); | 
| 250 | TRAP_IGNORE(iHttpClient->ClientRequestCompleteL(aError)); | |
| 2 | 251 | return KErrNone; | 
| 252 | } | |
| 253 | ||
| 254 | void CHttpEventHandler::SetSaveFileName(const TDesC &fName, TBool aContinue) | |
| 255 | 	{
 | |
| 164 
000f9fc147b2
Catch up with default branch; New v 27 SIS
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
90diff
changeset | 256 | 	DP1("CHttpEventHandler::SetSaveFileName, aContinue=%d", aContinue);
 | 
| 2 | 257 | iFileName.Copy(fName); | 
| 258 | iContinue = aContinue; | |
| 245 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 259 | |
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 260 | switch(fName[0]) | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 261 | 		{
 | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 262 | case 'C': | 
| 336 
3d6c1417e8bd
Merged all the later Symbian3 updates into Symbian1 branch; new SIS v. 1.00.32
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
284diff
changeset | 263 | case '\\': | 
| 245 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 264 | iDriveNo = EDriveC; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 265 | break; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 266 | case 'E': | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 267 | iDriveNo = EDriveE; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 268 | break; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 269 | case 'F': | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 270 | iDriveNo = EDriveF; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 271 | break; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 272 | case 'G': | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 273 | iDriveNo = EDriveG; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 274 | break; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 275 | default: | 
| 336 
3d6c1417e8bd
Merged all the later Symbian3 updates into Symbian1 branch; new SIS v. 1.00.32
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
284diff
changeset | 276 | Panic(EPodcatcherDownloadDrive); | 
| 245 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 277 | break; | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 278 | } | 
| 
3f57982a6f10
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
167diff
changeset | 279 | 	DP1("iDriveNo set to %d", iDriveNo);
 | 
| 2 | 280 | } | 
| 281 | ||
| 282 | void CHttpEventHandler::DumpRespHeadersL(RHTTPTransaction& aTrans) | |
| 283 | 	{
 | |
| 284 | RHTTPResponse resp = aTrans.Response(); | |
| 285 | RStringPool strP = aTrans.Session().StringPool(); | |
| 286 | RHTTPHeaders hdr = resp.GetHeaderCollection(); | |
| 287 | THTTPHdrFieldIter it = hdr.Fields(); | |
| 288 | ||
| 289 | TBuf<KMaxHeaderNameLen> fieldName16; | |
| 290 | TBuf<KMaxHeaderValueLen> fieldVal16; | |
| 291 | ||
| 292 | while (it.AtEnd() == EFalse) | |
| 293 | 		{
 | |
| 294 | RStringTokenF fieldName = it(); | |
| 295 | RStringF fieldNameStr = strP.StringF(fieldName); | |
| 296 | THTTPHdrVal fieldVal; | |
| 297 | if (hdr.GetField(fieldNameStr,0,fieldVal) == KErrNone) | |
| 298 | 			{
 | |
| 299 | const TDesC8& fieldNameDesC = fieldNameStr.DesC(); | |
| 300 | fieldName16.Copy(fieldNameDesC.Left(KMaxHeaderNameLen)); | |
| 301 | switch (fieldVal.Type()) | |
| 302 | 				{
 | |
| 303 | case THTTPHdrVal::KTIntVal: | |
| 304 | 				DP2("%S: %d", &fieldName16, fieldVal.Int());
 | |
| 305 | break; | |
| 306 | case THTTPHdrVal::KStrFVal: | |
| 307 | 				{
 | |
| 308 | RStringF fieldValStr = strP.StringF(fieldVal.StrF()); | |
| 309 | const TDesC8& fieldValDesC = fieldValStr.DesC(); | |
| 310 | fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen)); | |
| 311 | 				DP2("%S: %S", &fieldName16, &fieldVal16);
 | |
| 312 | } | |
| 313 | break; | |
| 314 | case THTTPHdrVal::KStrVal: | |
| 315 | 				{
 | |
| 316 | RString fieldValStr = strP.String(fieldVal.Str()); | |
| 317 | const TDesC8& fieldValDesC = fieldValStr.DesC(); | |
| 318 | fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen)); | |
| 319 | 				DP2("%S: %S", &fieldName16, &fieldVal16);
 | |
| 320 | } | |
| 321 | break; | |
| 322 | case THTTPHdrVal::KDateVal: | |
| 323 | 				{
 | |
| 324 | TDateTime date = fieldVal.DateTime(); | |
| 325 | } | |
| 326 | break; | |
| 327 | default: | |
| 328 | 				DP1("%S: <unrecognised value type>", &fieldName16);
 | |
| 329 | break; | |
| 330 | } | |
| 331 | ||
| 332 | // Display realm for WWW-Authenticate header | |
| 333 | RStringF wwwAuth = strP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable()); | |
| 334 | if (fieldNameStr == wwwAuth) | |
| 335 | 				{
 | |
| 336 | // check the auth scheme is 'basic' | |
| 337 | RStringF basic = strP.StringF(HTTP::EBasic,RHTTPSession::GetTable()); | |
| 338 | RStringF realm = strP.StringF(HTTP::ERealm,RHTTPSession::GetTable()); | |
| 339 | THTTPHdrVal realmVal; | |
| 340 | if ((fieldVal.StrF() == basic) && | |
| 341 | (!hdr.GetParam(wwwAuth, realm, realmVal))) | |
| 342 | 					{
 | |
| 343 | RStringF realmValStr = strP.StringF(realmVal.StrF()); | |
| 344 | fieldVal16.Copy(realmValStr.DesC()); | |
| 345 | 					DP1("Realm is: %S", &fieldVal16);
 | |
| 346 | } | |
| 347 | } | |
| 348 | } | |
| 349 | ++it; | |
| 350 | } | |
| 351 | } | |
| 352 | ||
| 353 | void CHttpEventHandler::DumpRespBody(RHTTPTransaction& aTrans) | |
| 354 | 	{
 | |
| 355 | MHTTPDataSupplier* body = aTrans.Response().Body(); | |
| 356 | TPtrC8 dataChunk; | |
| 357 | TBool isLast = body->GetNextDataPart(dataChunk); | |
| 358 | DumpIt(dataChunk); | |
| 359 | if (isLast) | |
| 360 | 		DP("Got last data chunk.");
 | |
| 361 | } | |
| 362 | ||
| 363 | ||
| 364 | void CHttpEventHandler::DumpIt(const TDesC8& aData) | |
| 365 | //Do a formatted dump of binary data | |
| 366 | 	{
 | |
| 367 | // Iterate the supplied block of data in blocks of cols=80 bytes | |
| 368 | const TInt cols=16; | |
| 369 | TInt pos = 0; | |
| 370 | TBuf<KMaxFileName - 2> logLine; | |
| 371 | TBuf<KMaxFileName - 2> anEntry; | |
| 372 | const TInt dataLength = aData.Length(); | |
| 373 | ||
| 374 | while (pos < dataLength) | |
| 375 | 		{
 | |
| 376 | //start-line hexadecimal( a 4 digit number) | |
| 377 | 		anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos);
 | |
| 378 | logLine.Append(anEntry); | |
| 379 | ||
| 380 | // Hex output | |
| 381 | TInt offset; | |
| 382 | for (offset = 0; offset < cols; ++offset) | |
| 383 | 			{
 | |
| 384 | if (pos + offset < aData.Length()) | |
| 385 | 				{
 | |
| 386 | TInt nextByte = aData[pos + offset]; | |
| 387 | 				anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte);
 | |
| 388 | logLine.Append(anEntry); | |
| 389 | } | |
| 390 | else | |
| 391 | 				{
 | |
| 392 | //fill the remaining spaces with blanks untill the cols-th Hex number | |
| 393 | 				anEntry.Format(TRefByValue<const TDesC>_L("   "));
 | |
| 394 | logLine.Append(anEntry); | |
| 395 | } | |
| 396 | } | |
| 397 | 			anEntry.Format(TRefByValue<const TDesC>_L(": "));
 | |
| 398 | logLine.Append(anEntry); | |
| 399 | ||
| 400 | // Char output | |
| 401 | for (offset = 0; offset < cols; ++offset) | |
| 402 | 			{
 | |
| 403 | if (pos + offset < aData.Length()) | |
| 404 | 				{
 | |
| 405 | TInt nextByte = aData[pos + offset]; | |
| 406 | if ((nextByte >= ' ') && (nextByte <= '~')) | |
| 407 | 					{
 | |
| 408 | 					anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte);
 | |
| 409 | logLine.Append(anEntry); | |
| 410 | } | |
| 411 | else | |
| 412 | 					{
 | |
| 413 | 					anEntry.Format(TRefByValue<const TDesC>_L("."));
 | |
| 414 | logLine.Append(anEntry); | |
| 415 | } | |
| 416 | } | |
| 417 | else | |
| 418 | 				{
 | |
| 419 | 				anEntry.Format(TRefByValue<const TDesC>_L(" "));
 | |
| 420 | logLine.Append(anEntry); | |
| 421 | } | |
| 422 | } | |
| 423 | logLine.Zero(); | |
| 424 | ||
| 425 | // Advance to next byte segment (1 seg= cols) | |
| 426 | pos += cols; | |
| 427 | } | |
| 428 | } | |
| 429 | ||
| 430 | void CHttpEventHandler::SetSilent(TBool aSilent) | |
| 431 | 	{
 | |
| 432 | iSilent = aSilent; | |
| 433 | } | |
| 434 | ||
| 435 | void CHttpEventHandler::CloseSaveFile() | |
| 436 | {
 | |
| 284 
69385a7c9810
Significant robustness improvements for ConnectionEngine
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
245diff
changeset | 437 | 	DP("CHttpEventHandler::CloseSaveFile BEGIN");
 | 
| 2 | 438 | if(iRespBody != NULL) | 
| 439 | 	{		
 | |
| 440 | if(iRespBodyFile.SubSessionHandle() != 0) | |
| 441 | 			{
 | |
| 442 | TInt size; | |
| 443 | iRespBodyFile.Size(size); | |
| 444 | 			DP2("Closing file at size %d, bytes downloaded %d", size, iBytesDownloaded);
 | |
| 445 | iRespBodyFile.Close(); | |
| 446 | } | |
| 447 | } | |
| 284 
69385a7c9810
Significant robustness improvements for ConnectionEngine
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
245diff
changeset | 448 | 	DP("CHttpEventHandler::CloseSaveFile BEGIN");
 | 
| 2 | 449 | } | 
| 450 |