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