Make wxWebResponse::Init() and Finalize() non-public
The former can be called from the derived class ctors while the latter only needs to be called from wxWebRequest itself, so just make it a friend: this is not ideal, but still better than leaving this public and simpler than any alternatives.
This commit is contained in:
@@ -154,10 +154,6 @@ public:
|
|||||||
|
|
||||||
wxString AsString() const;
|
wxString AsString() const;
|
||||||
|
|
||||||
bool Init();
|
|
||||||
|
|
||||||
void Finalize();
|
|
||||||
|
|
||||||
virtual wxString GetFileName() const;
|
virtual wxString GetFileName() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -166,15 +162,24 @@ protected:
|
|||||||
|
|
||||||
wxWebResponse(wxWebRequest& request);
|
wxWebResponse(wxWebRequest& request);
|
||||||
|
|
||||||
|
// Called from derived class ctor to finish initialization which can't be
|
||||||
|
// performed in ctor itself as it needs to use pure virtual method.
|
||||||
|
void Init();
|
||||||
|
|
||||||
void* GetDataBuffer(size_t sizeNeeded);
|
void* GetDataBuffer(size_t sizeNeeded);
|
||||||
|
|
||||||
void ReportDataReceived(size_t sizeReceived);
|
void ReportDataReceived(size_t sizeReceived);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Called by wxWebRequest only.
|
||||||
|
void Finalize();
|
||||||
|
|
||||||
wxMemoryBuffer m_readBuffer;
|
wxMemoryBuffer m_readBuffer;
|
||||||
mutable wxFFile m_file;
|
mutable wxFFile m_file;
|
||||||
mutable wxScopedPtr<wxInputStream> m_stream;
|
mutable wxScopedPtr<wxInputStream> m_stream;
|
||||||
|
|
||||||
|
friend class wxWebRequest;
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(wxWebResponse);
|
wxDECLARE_NO_COPY_CLASS(wxWebResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -260,7 +260,7 @@ wxWebResponse::~wxWebResponse()
|
|||||||
wxRemoveFile(m_file.GetName());
|
wxRemoveFile(m_file.GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxWebResponse::Init()
|
void wxWebResponse::Init()
|
||||||
{
|
{
|
||||||
if ( m_request.GetStorage() == wxWebRequest::Storage_File )
|
if ( m_request.GetStorage() == wxWebRequest::Storage_File )
|
||||||
{
|
{
|
||||||
@@ -274,15 +274,13 @@ bool wxWebResponse::Init()
|
|||||||
GetContentLength() > freeSpace )
|
GetContentLength() > freeSpace )
|
||||||
{
|
{
|
||||||
m_request.SetState(wxWebRequest::State_Failed, _("Not enough free disk space for download."));
|
m_request.SetState(wxWebRequest::State_Failed, _("Not enough free disk space for download."));
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpPrefix.SetName("wxd");
|
tmpPrefix.SetName("wxd");
|
||||||
wxFileName::CreateTempFileName(tmpPrefix.GetFullPath(), &m_file);
|
wxFileName::CreateTempFileName(tmpPrefix.GetFullPath(), &m_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxWebResponse::GetMimeType() const
|
wxString wxWebResponse::GetMimeType() const
|
||||||
|
@@ -63,6 +63,8 @@ wxWebResponseCURL::wxWebResponseCURL(wxWebRequest& request) :
|
|||||||
{
|
{
|
||||||
curl_easy_setopt(GetHandle(), CURLOPT_WRITEDATA, static_cast<void*>(this));
|
curl_easy_setopt(GetHandle(), CURLOPT_WRITEDATA, static_cast<void*>(this));
|
||||||
curl_easy_setopt(GetHandle(), CURLOPT_HEADERDATA, static_cast<void*>(this));
|
curl_easy_setopt(GetHandle(), CURLOPT_HEADERDATA, static_cast<void*>(this));
|
||||||
|
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxWebResponseCURL::WriteData(void* buffer, size_t size)
|
size_t wxWebResponseCURL::WriteData(void* buffer, size_t size)
|
||||||
@@ -192,7 +194,6 @@ void wxWebRequestCURL::Start()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_response.reset(new wxWebResponseCURL(*this));
|
m_response.reset(new wxWebResponseCURL(*this));
|
||||||
m_response->Init();
|
|
||||||
|
|
||||||
if ( m_dataSize )
|
if ( m_dataSize )
|
||||||
{
|
{
|
||||||
|
@@ -220,8 +220,11 @@ void wxWebRequestWinHTTP::CreateResponse()
|
|||||||
if ( ::WinHttpReceiveResponse(m_request, NULL) )
|
if ( ::WinHttpReceiveResponse(m_request, NULL) )
|
||||||
{
|
{
|
||||||
m_response.reset(new wxWebResponseWinHTTP(*this));
|
m_response.reset(new wxWebResponseWinHTTP(*this));
|
||||||
if ( !m_response->Init() )
|
// wxWebResponseWinHTTP ctor could have changed the state if its
|
||||||
|
// initialization failed, so check for this.
|
||||||
|
if ( GetState() == State_Failed )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int status = m_response->GetStatus();
|
int status = m_response->GetStatus();
|
||||||
if ( status == 401 || status == 407)
|
if ( status == 401 || status == 407)
|
||||||
{
|
{
|
||||||
@@ -364,6 +367,8 @@ wxWebResponseWinHTTP::wxWebResponseWinHTTP(wxWebRequestWinHTTP& request):
|
|||||||
if ( contentLengthStr.empty() ||
|
if ( contentLengthStr.empty() ||
|
||||||
!contentLengthStr.ToLongLong(&m_contentLength) )
|
!contentLengthStr.ToLongLong(&m_contentLength) )
|
||||||
m_contentLength = -1;
|
m_contentLength = -1;
|
||||||
|
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxWebResponseWinHTTP::GetURL() const
|
wxString wxWebResponseWinHTTP::GetURL() const
|
||||||
|
@@ -140,7 +140,6 @@ void wxWebRequestURLSession::Start()
|
|||||||
[session.GetDelegate() registerRequest:this task:m_task];
|
[session.GetDelegate() registerRequest:this task:m_task];
|
||||||
|
|
||||||
m_response.reset(new wxWebResponseURLSession(*this, m_task));
|
m_response.reset(new wxWebResponseURLSession(*this, m_task));
|
||||||
m_response->Init();
|
|
||||||
|
|
||||||
SetState(State_Active);
|
SetState(State_Active);
|
||||||
[m_task resume];
|
[m_task resume];
|
||||||
@@ -191,6 +190,8 @@ wxWebResponseURLSession::wxWebResponseURLSession(wxWebRequest& request, WX_NSURL
|
|||||||
wxWebResponse(request)
|
wxWebResponse(request)
|
||||||
{
|
{
|
||||||
m_task = [task retain];
|
m_task = [task retain];
|
||||||
|
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWebResponseURLSession::~wxWebResponseURLSession()
|
wxWebResponseURLSession::~wxWebResponseURLSession()
|
||||||
|
Reference in New Issue
Block a user