engine/src/HttpClient.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Sat, 13 Nov 2010 13:54:36 +0000
branch3rded
changeset 343 9c56bf585696
parent 177 269e3f3e544a
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
// 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"
60
4d230e702aa3 Moved development branch from MCL to FCL
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()
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
    22
  {	 
2
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
			}
177
269e3f3e544a Lots of fixes for 3rd edition. First test SIS file, 0.90(3)
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 164
diff changeset
   100
		else if( (iPodcastModel.SettingsEngine().SpecificIAP()))
2
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
			}
177
269e3f3e544a Lots of fixes for 3rd edition. First test SIS file, 0.90(3)
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 164
diff changeset
   104
//		else
269e3f3e544a Lots of fixes for 3rd edition. First test SIS file, 0.90(3)
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 164
diff changeset
   105
//			{
269e3f3e544a Lots of fixes for 3rd edition. First test SIS file, 0.90(3)
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 164
diff changeset
   106
//			iPodcastModel.ConnectionEngine().StartL(CConnectionEngine::EMobilityConnection);
269e3f3e544a Lots of fixes for 3rd edition. First test SIS file, 0.90(3)
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 164
diff changeset
   107
//			}
2
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
	{
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   114
	DP1("CHttpClient::ConnectCompleteL BEGIN, aErrorCode=%d", aErrorCode);
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   115
	DP1("    iWaitingForGet=%d", iWaitingForGet);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
	if(iWaitingForGet)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
		iWaitingForGet = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
		if( aErrorCode == KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
			RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
			RStringPool pool = iSession.StringPool();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
			// Attach to socket server
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
			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
   125
			// Attach to connection
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
			TInt connPtr = REINTERPRET_CAST(TInt, &iPodcastModel.ConnectionEngine().Connection());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
			connInfo.SetPropertyL(pool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal(connPtr));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
			iPodcastModel.SetProxyUsageIfNeededL(iSession);
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   130
			DoGetAfterConnectL();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
		else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
			ClientRequestCompleteL(KErrCouldNotConnect);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
			iSession.Close();			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
			}
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   137
		}
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   138
	DP("CHttpClient::ConnectCompleteL END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
	}
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
void CHttpClient::Disconnected()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
	iIsActive = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
	iSession.Close();
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
void  CHttpClient::DoGetAfterConnectL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
	{	
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   149
	DP("CHttpClient::DoGetAfterConnectL BEGIN");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
	// since nothing should be downloading now. Delete the handler
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
	if (iHandler)
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
		delete iHandler;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
		iHandler = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
		}
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
	iHandler = CHttpEventHandler::NewL(this, iObserver, iPodcastModel.FsSession());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
	iHandler->SetSilent(iSilentGet);
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
	TEntry entry;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
	TBuf8<KTempBufferSize> rangeText;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
	if (iResumeEnabled && iPodcastModel.FsSession().Entry(iCurrentFileName, entry) == KErrNone) {
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   164
		DP1("    Found file, with size=%d", entry.iSize);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
		// file exists, so we should probably resume
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
   166
		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
   167
		iHandler->SetSaveFileName(iCurrentFileName, ETrue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
	} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
		// otherwise just make sure the directory exists
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
		BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(),iCurrentFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
		iHandler->SetSaveFileName(iCurrentFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
	RStringPool strP = iSession.StringPool();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
	RStringF method;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
	method = strP.StringF(HTTP::EGET, RHTTPSession::GetTable());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
	iTrans = iSession.OpenTransactionL(iUriParser, *iHandler, method);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
	RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
	// Add headers appropriate to all methods
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
	SetHeaderL(hdr, HTTP::EAccept, KAccept);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
	TBuf<KTempBufferSize> range16;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
	range16.Copy(rangeText);
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   185
	DP1("    range text: %S", &range16);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
	if (rangeText.Length() > 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
		SetHeaderL(hdr, HTTP::ERange, rangeText);
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
	iTransactionCount++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
	// submit the transaction
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
	iTrans.SubmitL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
	iIsActive = ETrue;	
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   193
	DP("CHttpClient::DoGetAfterConnectL END");
2
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
TBool CHttpClient::GetL(const TDesC& aUrl, const TDesC& aFileName,  TBool aSilent) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
	DP("CHttpClient::Get START");
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   198
	DP2("Getting '%S' to '%S'", &aUrl, &aFileName);
69
4a65cc85c4f3 Updated package_definition.xml for 2.0.1 schema
teknolog
parents: 60
diff changeset
   199
	
4a65cc85c4f3 Updated package_definition.xml for 2.0.1 schema
teknolog
parents: 60
diff changeset
   200
	if (iIsActive)
4a65cc85c4f3 Updated package_definition.xml for 2.0.1 schema
teknolog
parents: 60
diff changeset
   201
		{
4a65cc85c4f3 Updated package_definition.xml for 2.0.1 schema
teknolog
parents: 60
diff changeset
   202
		return EFalse;
4a65cc85c4f3 Updated package_definition.xml for 2.0.1 schema
teknolog
parents: 60
diff changeset
   203
		}
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 69
diff changeset
   204
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 69
diff changeset
   205
	DP1("Getting URL: %S", &aUrl);
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 69
diff changeset
   206
	DP1("Writing file: %S", &aFileName);
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 69
diff changeset
   207
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
	iCurrentURL.Copy(aUrl);	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
	TInt urlError = iUriParser.Parse(iCurrentURL);
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
	if(urlError != KErrNone ||!iUriParser.IsSchemeValid())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
		{		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
		iCurrentURL = KNullDesC8;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
		iSession.Close();		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
		iObserver.CompleteL(this, KErrHttpInvalidUri);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
		return EFalse;		
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
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
	iSilentGet = aSilent;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
	iCurrentFileName.Copy(aFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
	if (iTransactionCount == 0) 
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("CHttpClient::GetL\t*** Opening HTTP session ***");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
		iSession.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
		iSession.OpenL();
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   228
		iWaitingForGet = ETrue;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
		ConnectHttpSessionL();			
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
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
		{
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   233
		iWaitingForGet = EFalse;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
		DoGetAfterConnectL();		
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
	return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
void CHttpClient::Stop()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
	iIsActive = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
	if(iHandler != NULL)
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
		// cancel the ongoing transaction
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
		iTrans.Cancel();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
		iTransactionCount = 0;
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
		// make sure that we save the file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
		iHandler->CloseSaveFile();
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
		// 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
   252
		delete iHandler;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
		iHandler = NULL;
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
		// close the session
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
		DP("CHttpClient::Stop\t*** Closing HTTP session ***");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
		iSession.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
	TRAP_IGNORE(iObserver.CompleteL(this, KErrDisconnected));
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
	}
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
void CHttpClient::ClientRequestCompleteL(TInt aErrorCode) {
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   265
	DP1("CHttpClient::ClientRequestCompleteL BEGIN, aErrorCode=%d", aErrorCode);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
	iIsActive = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
	iObserver.CompleteL(this, aErrorCode);
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   268
	DP1("    iTransactionCount=%d", iTransactionCount);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
	if(iTransactionCount>0)
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
		iTransactionCount--;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
		if(iTransactionCount == 0) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
			DP("CHttpClient::ClientRequestCompleteL\t*** Closing HTTP session ***");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
			delete iHandler;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
			iHandler = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
			iSession.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
		}
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 177
diff changeset
   281
	DP("CHttpClient::ClientRequestCompleteL END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
}