Move SetDefaultTimeout to wxProtocol and set it to 60 seconds for both wxHTTP and wxFTP
Move SetPassword and SetUser implementations to wxProtocol to avoid code redundancy Make const-correct various getters Reorganize wxFTP docs Move wxStringToStringHashMap to hashmap.h and document its existance git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58137 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -18,18 +18,20 @@
|
||||
|
||||
#include "wx/protocol/protocol.h"
|
||||
|
||||
class WXDLLIMPEXP_NET wxFileProto: public wxProtocol {
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxFileProto)
|
||||
DECLARE_PROTOCOL(wxFileProto)
|
||||
protected:
|
||||
wxProtocolError m_error;
|
||||
class WXDLLIMPEXP_NET wxFileProto: public wxProtocol
|
||||
{
|
||||
public:
|
||||
wxFileProto();
|
||||
virtual ~wxFileProto();
|
||||
wxFileProto();
|
||||
virtual ~wxFileProto();
|
||||
|
||||
wxProtocolError GetError() { return m_error; }
|
||||
bool Abort() { return TRUE; }
|
||||
wxInputStream *GetInputStream(const wxString& path);
|
||||
bool Abort() { return true; }
|
||||
wxString GetContentType() const { return wxEmptyString; }
|
||||
|
||||
wxInputStream *GetInputStream(const wxString& path);
|
||||
|
||||
protected:
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxFileProto)
|
||||
DECLARE_PROTOCOL(wxFileProto)
|
||||
};
|
||||
|
||||
#endif // wxUSE_PROTOCOL_FILE
|
||||
|
@@ -35,31 +35,27 @@ public:
|
||||
virtual ~wxFTP();
|
||||
|
||||
// Connecting and disconnecting
|
||||
void SetUser(const wxString& user) { m_user = user; }
|
||||
void SetPassword(const wxString& passwd) { m_passwd = passwd; }
|
||||
|
||||
bool Connect(const wxSockAddress& addr, bool wait = true);
|
||||
bool Connect(const wxString& host);
|
||||
|
||||
// disconnect
|
||||
virtual bool Close(); // does NOT set m_lastError
|
||||
virtual bool Close();
|
||||
|
||||
// Parameters set up
|
||||
|
||||
// set transfer mode now
|
||||
void SetPassive(bool pasv) { m_bPassive = pasv; }
|
||||
void SetDefaultTimeout(wxUint32 Value);
|
||||
bool SetBinary() { return SetTransferMode(BINARY); }
|
||||
bool SetAscii() { return SetTransferMode(ASCII); }
|
||||
bool SetTransferMode(TransferMode mode);
|
||||
|
||||
// Generic FTP interface
|
||||
|
||||
// the error code
|
||||
virtual wxProtocolError GetError() { return m_lastError; }
|
||||
// FTP doesn't know the MIME type of the last downloaded/uploaded file
|
||||
virtual wxString GetContentType() const { return wxEmptyString; }
|
||||
|
||||
// the last FTP server reply
|
||||
const wxString& GetLastResult() { return m_lastResult; }
|
||||
const wxString& GetLastResult() const { return m_lastResult; }
|
||||
|
||||
// send any FTP command (should be full FTP command line but without
|
||||
// trailing "\r\n") and return its return code
|
||||
@@ -68,6 +64,7 @@ public:
|
||||
// check that the command returned the given code
|
||||
bool CheckCommand(const wxString& command, char expectedReturn)
|
||||
{
|
||||
// SendCommand() does updates m_lastError
|
||||
return SendCommand(command) == expectedReturn;
|
||||
}
|
||||
|
||||
@@ -119,11 +116,6 @@ public:
|
||||
bool details = false);
|
||||
|
||||
protected:
|
||||
// just change access from public to protected for this wxSocketBase function:
|
||||
// use SetDefaultTimeout instead which also sets our m_uiDefaultTimeout var
|
||||
virtual void SetTimeout(long seconds)
|
||||
{ wxSocketBase::SetTimeout(seconds); }
|
||||
|
||||
// this executes a simple ftp command with the given argument and returns
|
||||
// true if it its return code starts with '2'
|
||||
bool DoSimpleCommand(const wxChar *command,
|
||||
@@ -150,30 +142,27 @@ protected:
|
||||
wxSocketBase *AcceptIfActive(wxSocketBase *sock);
|
||||
|
||||
|
||||
wxString m_user,
|
||||
m_passwd;
|
||||
// internal variables:
|
||||
|
||||
wxString m_lastResult;
|
||||
wxProtocolError m_lastError;
|
||||
wxString m_lastResult;
|
||||
|
||||
// true if there is an FTP transfer going on
|
||||
bool m_streaming;
|
||||
bool m_streaming;
|
||||
|
||||
// although this should be set to ASCII by default according to STD9,
|
||||
// we will use BINARY transfer mode by default for backwards compatibility
|
||||
TransferMode m_currentTransfermode;
|
||||
|
||||
friend class wxInputFTPStream;
|
||||
friend class wxOutputFTPStream;
|
||||
TransferMode m_currentTransfermode;
|
||||
|
||||
bool m_bPassive;
|
||||
wxUint32 m_uiDefaultTimeout;
|
||||
|
||||
// following is true when a read or write times out, we then assume
|
||||
// the connection is dead and abort. we avoid additional delays this way
|
||||
bool m_bEncounteredError;
|
||||
|
||||
|
||||
friend class wxInputFTPStream;
|
||||
friend class wxOutputFTPStream;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxFTP)
|
||||
DECLARE_PROTOCOL(wxFTP)
|
||||
};
|
||||
|
@@ -18,71 +18,64 @@
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/protocol/protocol.h"
|
||||
|
||||
WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxString, wxStringToStringHashMap,
|
||||
class WXDLLIMPEXP_NET );
|
||||
|
||||
class WXDLLIMPEXP_NET wxHTTP : public wxProtocol
|
||||
{
|
||||
public:
|
||||
wxHTTP();
|
||||
virtual ~wxHTTP();
|
||||
wxHTTP();
|
||||
virtual ~wxHTTP();
|
||||
|
||||
virtual bool Connect(const wxString& host, unsigned short port);
|
||||
virtual bool Connect(const wxString& host) { return Connect(host, 0); }
|
||||
virtual bool Connect(const wxSockAddress& addr, bool wait);
|
||||
bool Abort();
|
||||
wxInputStream *GetInputStream(const wxString& path);
|
||||
inline wxProtocolError GetError() { return m_perr; }
|
||||
wxString GetContentType();
|
||||
virtual bool Connect(const wxString& host, unsigned short port);
|
||||
virtual bool Connect(const wxString& host) { return Connect(host, 0); }
|
||||
virtual bool Connect(const wxSockAddress& addr, bool wait);
|
||||
bool Abort();
|
||||
|
||||
void SetHeader(const wxString& header, const wxString& h_data);
|
||||
wxString GetHeader(const wxString& header) const;
|
||||
void SetPostBuffer(const wxString& post_buf);
|
||||
wxInputStream *GetInputStream(const wxString& path);
|
||||
|
||||
void SetProxyMode(bool on);
|
||||
wxString GetContentType() const;
|
||||
wxString GetHeader(const wxString& header) const;
|
||||
int GetResponse() const { return m_http_response; }
|
||||
|
||||
int GetResponse() { return m_http_response; }
|
||||
|
||||
virtual void SetUser(const wxString& user) { m_username = user; }
|
||||
virtual void SetPassword(const wxString& passwd ) { m_password = passwd; }
|
||||
void SetHeader(const wxString& header, const wxString& h_data);
|
||||
void SetPostBuffer(const wxString& post_buf);
|
||||
void SetProxyMode(bool on);
|
||||
|
||||
protected:
|
||||
enum wxHTTP_Req
|
||||
{
|
||||
wxHTTP_GET,
|
||||
wxHTTP_POST,
|
||||
wxHTTP_HEAD
|
||||
};
|
||||
enum wxHTTP_Req
|
||||
{
|
||||
wxHTTP_GET,
|
||||
wxHTTP_POST,
|
||||
wxHTTP_HEAD
|
||||
};
|
||||
|
||||
typedef wxStringToStringHashMap::iterator wxHeaderIterator;
|
||||
typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator;
|
||||
typedef wxStringToStringHashMap::iterator wxHeaderIterator;
|
||||
typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator;
|
||||
|
||||
bool BuildRequest(const wxString& path, wxHTTP_Req req);
|
||||
void SendHeaders();
|
||||
bool ParseHeaders();
|
||||
bool BuildRequest(const wxString& path, wxHTTP_Req req);
|
||||
void SendHeaders();
|
||||
bool ParseHeaders();
|
||||
|
||||
wxString GenerateAuthString(const wxString& user, const wxString& pass) const;
|
||||
wxString GenerateAuthString(const wxString& user, const wxString& pass) const;
|
||||
|
||||
// find the header in m_headers
|
||||
wxHeaderIterator FindHeader(const wxString& header);
|
||||
wxHeaderConstIterator FindHeader(const wxString& header) const;
|
||||
// find the header in m_headers
|
||||
wxHeaderIterator FindHeader(const wxString& header);
|
||||
wxHeaderConstIterator FindHeader(const wxString& header) const;
|
||||
|
||||
// deletes the header value strings
|
||||
void ClearHeaders();
|
||||
// deletes the header value strings
|
||||
void ClearHeaders();
|
||||
|
||||
wxProtocolError m_perr;
|
||||
wxStringToStringHashMap m_headers;
|
||||
bool m_read,
|
||||
m_proxy_mode;
|
||||
wxSockAddress *m_addr;
|
||||
wxString m_post_buf;
|
||||
int m_http_response;
|
||||
wxString m_username;
|
||||
wxString m_password;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxHTTP)
|
||||
DECLARE_PROTOCOL(wxHTTP)
|
||||
DECLARE_NO_COPY_CLASS(wxHTTP)
|
||||
// internal variables:
|
||||
|
||||
wxStringToStringHashMap m_headers;
|
||||
bool m_read,
|
||||
m_proxy_mode;
|
||||
wxSockAddress *m_addr;
|
||||
wxString m_post_buf;
|
||||
int m_http_response;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxHTTP)
|
||||
DECLARE_PROTOCOL(wxHTTP)
|
||||
DECLARE_NO_COPY_CLASS(wxHTTP)
|
||||
};
|
||||
|
||||
#endif // wxUSE_PROTOCOL_HTTP
|
||||
|
@@ -58,8 +58,8 @@ public:
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
bool Reconnect();
|
||||
virtual bool Connect( const wxString& WXUNUSED(host) ) { return FALSE; }
|
||||
virtual bool Connect( const wxSockAddress& addr, bool WXUNUSED(wait) = TRUE)
|
||||
virtual bool Connect( const wxString& WXUNUSED(host) ) { return false; }
|
||||
virtual bool Connect( const wxSockAddress& addr, bool WXUNUSED(wait) = true)
|
||||
{ return wxSocketClient::Connect(addr); }
|
||||
|
||||
// read a '\r\n' terminated line from the given socket and put it in
|
||||
@@ -73,10 +73,31 @@ public:
|
||||
|
||||
virtual bool Abort() = 0;
|
||||
virtual wxInputStream *GetInputStream(const wxString& path) = 0;
|
||||
virtual wxProtocolError GetError() = 0;
|
||||
virtual wxString GetContentType() { return wxEmptyString; }
|
||||
virtual void SetUser(const wxString& WXUNUSED(user)) {}
|
||||
virtual void SetPassword(const wxString& WXUNUSED(passwd) ) {}
|
||||
virtual wxString GetContentType() const = 0;
|
||||
|
||||
// the error code
|
||||
virtual wxProtocolError GetError() const { return m_lastError; }
|
||||
|
||||
void SetUser(const wxString& user) { m_username = user; }
|
||||
void SetPassword(const wxString& passwd) { m_password = passwd; }
|
||||
|
||||
virtual void SetDefaultTimeout(wxUint32 Value);
|
||||
|
||||
// override wxSocketBase::SetTimeout function to avoid that the internal
|
||||
// m_uiDefaultTimeout goes out-of-sync:
|
||||
virtual void SetTimeout(long seconds)
|
||||
{ SetDefaultTimeout(seconds); }
|
||||
|
||||
|
||||
protected:
|
||||
// the timeout associated with the protocol:
|
||||
wxUint32 m_uiDefaultTimeout;
|
||||
|
||||
wxString m_username;
|
||||
wxString m_password;
|
||||
|
||||
// this must be always updated by the derived classes!
|
||||
wxProtocolError m_lastError;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol)
|
||||
|
Reference in New Issue
Block a user