engine/src/HttpClient.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Sat, 16 Oct 2010 18:04:09 +0100
branchRCL_3
changeset 243 44d205147a83
parent 126 c2f1ea38ec70
child 228 c553fa9dcbe5
child 285 4d42a5e09930
permissions -rw-r--r--
Fix for bug 3730 by switching to proper S3 context menu handling
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
// HttpClient.cpp
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     2
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
#include <e32base.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     5
#include <http/rhttpheaders.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     6
#include <http.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     7
#include <commdb.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     8
#include <eikenv.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     9
#include <es_sock.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    10
#include <bautils.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    11
#include <CommDbConnPref.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    12
#include "debug.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
#include "constants.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
#include "HttpClient.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
#include "connectionengine.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
#include "settingsengine.h"
114
27f6f5827e5d Cleaned up panic handling
teknolog
parents: 2
diff changeset
    17
#include "Podcatcher.pan"
2
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
const TInt KTempBufferSize = 100;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
CHttpClient::~CHttpClient()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
  {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
  if (iHandler)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
  	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
  	iHandler->CloseSaveFile();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
	delete iHandler;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
  	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
  iSession.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
  }
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
CHttpClient* CHttpClient::NewL(CPodcastModel& aPodcastModel, MHttpClientObserver& aObserver)
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
  CHttpClient* me = NewLC(aPodcastModel, aObserver);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
  CleanupStack::Pop(me);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
  return me;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
  }
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
CHttpClient::CHttpClient(CPodcastModel& aPodcastModel, MHttpClientObserver& aObserver) : iPodcastModel(aPodcastModel), iObserver(aObserver)
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
  iResumeEnabled = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
  }
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
CHttpClient* CHttpClient::NewLC(CPodcastModel& aPodcastModel, MHttpClientObserver& aObserver)
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
  CHttpClient* me = new (ELeave) CHttpClient(aPodcastModel, aObserver);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
  CleanupStack::PushL(me);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
  me->ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
  return me;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
void CHttpClient::ConstructL()
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
  iPodcastModel.ConnectionEngine().AddObserver(this);
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
void CHttpClient::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
	RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
	THTTPHdrVal val(valStr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
	aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField, RHTTPSession::GetTable()), val);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
	valStr.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
TBool CHttpClient::IsActive()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
	return iIsActive;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
	}
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
void CHttpClient::SetResumeEnabled(TBool aEnabled)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
	iResumeEnabled = aEnabled;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
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
void CHttpClient::ConnectHttpSessionL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
	DP("ConnectHttpSessionL START");	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
	CConnectionEngine::TConnectionState connState = iPodcastModel.ConnectionEngine().ConnectionState();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
	if(connState == CConnectionEngine::EConnected)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
		DP("ConnectionState == CConnectionEngine::EConnected");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
		// Session already connected, call connect complete directly but return status since URLs or so might be faulty
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
		ConnectCompleteL(KErrNone);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
		return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
	if(connState == CConnectionEngine::ENotConnected)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
		DP1("SpecificIAP() == %d",iPodcastModel.SettingsEngine().SpecificIAP());
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
		if(iPodcastModel.SettingsEngine().SpecificIAP() == -1)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
			iPodcastModel.ConnectionEngine().StartL(CConnectionEngine::EUserSelectConnection);	
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
		else if ( iPodcastModel.SettingsEngine().SpecificIAP() == 0 )
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
			iPodcastModel.ConnectionEngine().StartL(CConnectionEngine::EDefaultConnection);	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
		else if( (iPodcastModel.SettingsEngine().SpecificIAP()&KUseIAPFlag))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
			iPodcastModel.ConnectionEngine().StartL(CConnectionEngine::EIAPConnection);
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
			iPodcastModel.ConnectionEngine().StartL(CConnectionEngine::EMobilityConnection);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
	DP("ConnectHttpSessionL END");	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
void CHttpClient::ConnectCompleteL(TInt aErrorCode)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
	if(iWaitingForGet)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
		iWaitingForGet = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
		if( aErrorCode == KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
			RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
			RStringPool pool = iSession.StringPool();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
			// Attach to socket server
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
			connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable()), THTTPHdrVal(iPodcastModel.ConnectionEngine().SockServ().Handle()));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
			// Attach to connection
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
			TInt connPtr = REINTERPRET_CAST(TInt, &iPodcastModel.ConnectionEngine().Connection());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
			connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal(connPtr));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
			iPodcastModel.SetProxyUsageIfNeededL(iSession);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
			DoGetAfterConnectL();		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
		else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
			ClientRequestCompleteL(KErrCouldNotConnect);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
			iSession.Close();			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
			}
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
void CHttpClient::Disconnected()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
	iIsActive = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
	iSession.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
	}
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
void  CHttpClient::DoGetAfterConnectL()
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
	// since nothing should be downloading now. Delete the handler
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
	if (iHandler)
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
		delete iHandler;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
		iHandler = NULL;
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
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
	iHandler = CHttpEventHandler::NewL(this, iObserver, iPodcastModel.FsSession());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
	iHandler->SetSilent(iSilentGet);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
	TEntry entry;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
	TBuf8<KTempBufferSize> rangeText;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
	if (iResumeEnabled && iPodcastModel.FsSession().Entry(iCurrentFileName, entry) == KErrNone) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
		DP1("Found file, with size=%d", entry.iSize);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
		// file exists, so we should probably resume
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 114
diff changeset
   163
		rangeText.Format(_L8("bytes=%d-"), (entry.iSize-KByteOverlap > 0 ? entry.iSize-KByteOverlap : 0));
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
		iHandler->SetSaveFileName(iCurrentFileName, ETrue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
	} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
		// otherwise just make sure the directory exists
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
		BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(),iCurrentFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
		iHandler->SetSaveFileName(iCurrentFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
	}
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
	RStringPool strP = iSession.StringPool();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
	RStringF method;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
	method = strP.StringF(HTTP::EGET, RHTTPSession::GetTable());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
	iTrans = iSession.OpenTransactionL(iUriParser, *iHandler, method);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
	RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
	// Add headers appropriate to all methods
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
	SetHeaderL(hdr, HTTP::EAccept, KAccept);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
	TBuf<KTempBufferSize> range16;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
	range16.Copy(rangeText);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
	DP1("range text: %S", &range16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
	if (rangeText.Length() > 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
		SetHeaderL(hdr, HTTP::ERange, rangeText);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
	iTransactionCount++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
	// submit the transaction
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
	iTrans.SubmitL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
	iIsActive = ETrue;	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
	DP("CHttpClient::Get END");		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
TBool CHttpClient::GetL(const TDesC& aUrl, const TDesC& aFileName,  TBool aSilent) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
	DP("CHttpClient::Get START");
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 115
diff changeset
   195
	DP2("Getting '%S' to '%S'", &aUrl, &aFileName);
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 115
diff changeset
   196
	
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 115
diff changeset
   197
	if (iIsActive)
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 115
diff changeset
   198
		{
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 115
diff changeset
   199
		return EFalse;
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 115
diff changeset
   200
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
	iCurrentURL.Copy(aUrl);	
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
	TInt urlError = iUriParser.Parse(iCurrentURL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
	if(urlError != KErrNone ||!iUriParser.IsSchemeValid())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
		{		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
		iCurrentURL = KNullDesC8;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
		iSession.Close();		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
		iObserver.CompleteL(this, KErrHttpInvalidUri);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
		return EFalse;		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
		}	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
	iSilentGet = aSilent;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
	iCurrentFileName.Copy(aFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
	iWaitingForGet = ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
	if (iTransactionCount == 0) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
		DP("CHttpClient::GetL\t*** Opening HTTP session ***");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
		iSession.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
		iSession.OpenL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
		ConnectHttpSessionL();			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
		DoGetAfterConnectL();		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
	return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
void CHttpClient::Stop()
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
	iIsActive = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
	if(iHandler != NULL)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
		// cancel the ongoing transaction
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
		iTrans.Cancel();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
		iTransactionCount = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
		// make sure that we save the file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
		iHandler->CloseSaveFile();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
		// we could now delete the handler since a new will be created
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
		delete iHandler;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
		iHandler = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
		// close the session
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
		DP("CHttpClient::Stop\t*** Closing HTTP session ***");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
		iSession.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
	TRAP_IGNORE(iObserver.CompleteL(this, KErrDisconnected));
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
void CHttpClient::ClientRequestCompleteL(TInt aErrorCode) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
	iIsActive = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
	iObserver.CompleteL(this, aErrorCode);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
	DP("CHttpClient::ClientRequestCompleteL");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
	if(iTransactionCount>0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
		iTransactionCount--;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
		if(iTransactionCount == 0) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
			DP("CHttpClient::ClientRequestCompleteL\t*** Closing HTTP session ***");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
			delete iHandler;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
			iHandler = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
			iSession.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
}