WX_DECLARE_HASH_MAP_WITH_DECL( long, long, wxIntegerHash, wxIntegerEqual,
wxLongToLongHashMap, class WXDLLIMPEXP_BASE );
+WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxString, wxStringToStringHashMap,
+ class WXDLLIMPEXP_BASE );
+
#endif // _WX_HASHMAP_H_
#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();
+
+ bool Abort() { return true; }
+ wxString GetContentType() const { return wxEmptyString; }
- wxProtocolError GetError() { return m_error; }
- bool Abort() { return TRUE; }
- wxInputStream *GetInputStream(const wxString& path);
+ wxInputStream *GetInputStream(const wxString& path);
+
+protected:
+ DECLARE_DYNAMIC_CLASS_NO_COPY(wxFileProto)
+ DECLARE_PROTOCOL(wxFileProto)
};
#endif // wxUSE_PROTOCOL_FILE
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
// check that the command returned the given code
bool CheckCommand(const wxString& command, char expectedReturn)
{
+ // SendCommand() does updates m_lastError
return SendCommand(command) == expectedReturn;
}
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,
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)
};
#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();
-
- 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();
+ wxHTTP();
+ virtual ~wxHTTP();
- void SetHeader(const wxString& header, const wxString& h_data);
- wxString GetHeader(const wxString& header) const;
- void SetPostBuffer(const wxString& post_buf);
+ 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 SetProxyMode(bool on);
+ wxInputStream *GetInputStream(const wxString& path);
- int GetResponse() { return m_http_response; }
+ wxString GetContentType() const;
+ wxString GetHeader(const wxString& header) const;
+ int GetResponse() const { 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
- };
-
- typedef wxStringToStringHashMap::iterator wxHeaderIterator;
- typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator;
-
- bool BuildRequest(const wxString& path, wxHTTP_Req req);
- void SendHeaders();
- bool ParseHeaders();
-
- 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;
-
- // 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)
+ enum wxHTTP_Req
+ {
+ wxHTTP_GET,
+ wxHTTP_POST,
+ wxHTTP_HEAD
+ };
+
+ typedef wxStringToStringHashMap::iterator wxHeaderIterator;
+ typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator;
+
+ bool BuildRequest(const wxString& path, wxHTTP_Req req);
+ void SendHeaders();
+ bool ParseHeaders();
+
+ 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;
+
+ // deletes the header value strings
+ void ClearHeaders();
+
+
+ // 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
#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
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)
This is a simple, type-safe, and reasonably efficient hash map class,
whose interface is a subset of the interface of STL containers.
In particular, the interface is modeled after std::map, and the various,
- non-standard, std::hash_map.
+ non-standard, std::hash_map (http://www.cppreference.com/wiki/stl/map/start).
Example:
@code
@endcode
The HASH_T and KEY_EQ_T are the types used for the hashing function and
key comparison. wxWidgets provides three predefined hashing functions:
- wxIntegerHash for integer types ( int, long, short, and their unsigned counterparts ),
- wxStringHash for strings ( wxString, wxChar*, char* ), and wxPointerHash for
+ @c wxIntegerHash for integer types ( int, long, short, and their unsigned counterparts ),
+ @c wxStringHash for strings ( wxString, wxChar*, char* ), and @c wxPointerHash for
any kind of pointer.
- Similarly three equality predicates: wxIntegerEqual, wxStringEqual,
- wxPointerEqual are provided.
+ Similarly three equality predicates: @c wxIntegerEqual, @c wxStringEqual,
+ @c wxPointerEqual are provided.
Using this you could declare a hash map mapping int values to wxString like this:
@code
it + 3, it1 - it2.
+ @section hashmap_predef Predefined hashmap types
+
+ wxWidgets defines the following hashmap types:
+ - wxLongToLongHashMap (uses long both for keys and values)
+ - wxStringToStringHashMap (uses wxString both for keys and values)
+
+
@library{wxbase}
@category{containers}
*/
@class wxFTP
wxFTP can be used to establish a connection to an FTP server and perform all the
- usual operations. Please consult the RFC 959 for more details about the FTP
- protocol.
+ usual operations. Please consult the RFC 959 (http://www.w3.org/Protocols/rfc959/)
+ for more details about the FTP protocol.
+
+ wxFTP can thus be used to create a (basic) FTP @b client.
To use a command which doesn't involve file transfer (i.e. directory oriented
commands) you just need to call a corresponding member function or use the
ftp.SetUser("user");
ftp.SetPassword("password");
- if ( !ftp.Connect("ftp.wxwindows.org") )
+ if ( !ftp.Connect("ftp.wxwidgets.org") )
{
wxLogError("Couldn't connect");
return;
}
- ftp.ChDir("/pub");
- wxInputStream *in = ftp.GetInputStream("wxWidgets-4.2.0.tar.gz");
+ ftp.ChDir("/pub/2.8.9);
+ wxInputStream *i = ftp.GetInputStream("wxWidgets-2.8.9.tar.bz2");
if ( !in )
{
wxLogError("Coudln't get file");
delete [] data;
delete in;
}
+
+ // gracefully close the connection to the server
+ ftp.Close();
@endcode
To upload a file you would do (assuming the connection to the server was opened
*/
virtual ~wxFTP();
+
+
+ /**
+ @name Functions for managing the FTP connection
+ */
+ //@{
+
/**
Aborts the download currently in process, returns @true if ok, @false
if an error occurred.
virtual bool Abort();
/**
- Change the current FTP working directory.
- Returns @true if successful.
+ Gracefully closes the connection with the server.
*/
- bool ChDir(const wxString& dir);
+ virtual bool Close();
/**
Send the specified @a command to the FTP server. @a ret specifies
*/
bool CheckCommand(const wxString& command, char ret);
+ /**
+ Returns the last command result, i.e. the full server reply for the last command.
+ */
+ const wxString& GetLastResult();
+
+ /**
+ Send the specified @a command to the FTP server and return the first
+ character of the return code.
+ */
+ char SendCommand(const wxString& command);
+
+ /**
+ Sets the transfer mode to ASCII. It will be used for the next transfer.
+ */
+ bool SetAscii();
+
+ /**
+ Sets the transfer mode to binary. It will be used for the next transfer.
+ */
+ bool SetBinary();
+
+ /**
+ If @a pasv is @true, passive connection to the FTP server is used.
+
+ This is the default as it works with practically all firewalls.
+ If the server doesn't support passive mode, you may call this function
+ with @false as argument to use an active connection.
+ */
+ void SetPassive(bool pasv);
+
+ /**
+ Sets the password to be sent to the FTP server to be allowed to log in.
+ */
+ virtual void SetPassword(const wxString& passwd);
+
+ /**
+ Sets the transfer mode to the specified one. It will be used for the next
+ transfer.
+
+ If this function is never called, binary transfer mode is used by default.
+ */
+ bool SetTransferMode(TransferMode mode);
+
+ /**
+ Sets the user name to be sent to the FTP server to be allowed to log in.
+ */
+ virtual void SetUser(const wxString& user);
+
+ //@}
+
+
+
+ /**
+ @name Filesystem commands
+ */
+ //@{
+
+ /**
+ Change the current FTP working directory.
+ Returns @true if successful.
+ */
+ bool ChDir(const wxString& dir);
+
+ /**
+ Create the specified directory in the current FTP working directory.
+ Returns @true if successful.
+ */
+ bool MkDir(const wxString& dir);
+
+ /**
+ Returns the current FTP working directory.
+ */
+ wxString Pwd();
+
+ /**
+ Rename the specified @a src element to @e dst. Returns @true if successful.
+ */
+ bool Rename(const wxString& src, const wxString& dst);
+
+ /**
+ Remove the specified directory from the current FTP working directory.
+ Returns @true if successful.
+ */
+ bool RmDir(const wxString& dir);
+
+ /**
+ Delete the file specified by @e path. Returns @true if successful.
+ */
+ bool RmFile(const wxString& path);
+
/**
Returns @true if the given remote file exists, @false otherwise.
*/
bool GetFilesList(wxArrayString& files,
const wxString& wildcard = wxEmptyString);
+ //@}
+
+
+ /**
+ @name Download and upload functions
+ */
+
+ //@{
/**
Creates a new input stream on the specified path.
You will be notified when the EOF is reached by an error.
@return Returns @NULL if an error occurred (it could be a network failure
- or the fact that the file doesn't exist).
+ or the fact that the file doesn't exist).
*/
virtual wxInputStream* GetInputStream(const wxString& path);
/**
- Returns the last command result, i.e. the full server reply for the last command.
- */
- const wxString& GetLastResult();
-
- /**
- Initializes an output stream to the specified @e file.
+ Initializes an output stream to the specified @a file.
The returned stream has all but the seek functionality of wxStreams.
When the user finishes writing data, he has to delete the stream to close it.
@return An initialized write-only stream.
-
- @see wxOutputStream
+ Returns @NULL if an error occurred (it could be a network failure
+ or the fact that the file doesn't exist).
*/
virtual wxOutputStream* GetOutputStream(const wxString& file);
- /**
- Create the specified directory in the current FTP working directory.
- Returns @true if successful.
- */
- bool MkDir(const wxString& dir);
-
- /**
- Returns the current FTP working directory.
- */
- wxString Pwd();
-
- /**
- Rename the specified @a src element to @e dst. Returns @true if successful.
- */
- bool Rename(const wxString& src, const wxString& dst);
-
- /**
- Remove the specified directory from the current FTP working directory.
- Returns @true if successful.
- */
- bool RmDir(const wxString& dir);
-
- /**
- Delete the file specified by @e path. Returns @true if successful.
- */
- bool RmFile(const wxString& path);
-
- /**
- Send the specified @a command to the FTP server and return the first
- character of the return code.
- */
- char SendCommand(const wxString& command);
-
- /**
- Sets the transfer mode to ASCII. It will be used for the next transfer.
- */
- bool SetAscii();
-
- /**
- Sets the transfer mode to binary (IMAGE). It will be used for the next transfer.
- */
- bool SetBinary();
-
- /**
- If @a pasv is @true, passive connection to the FTP server is used.
-
- This is the default as it works with practically all firewalls.
- If the server doesn't support passive move, you may call this function with
- @false argument to use active connection.
- */
- void SetPassive(bool pasv);
-
- /**
- Sets the password to be sent to the FTP server to be allowed to log in.
- */
- virtual void SetPassword(const wxString& passwd);
-
- /**
- Sets the transfer mode to the specified one. It will be used for the next
- transfer.
-
- If this function is never called, binary transfer mode is used by default.
- */
- bool SetTransferMode(TransferMode mode);
-
- /**
- Sets the user name to be sent to the FTP server to be allowed to log in.
- */
- virtual void SetUser(const wxString& user);
+ //@}
};
wxHTTP can be used to establish a connection to an HTTP server.
+ wxHTTP can thus be used to create a (basic) HTTP @b client.
+
@library{wxnet}
@category{net}
class wxHTTP : public wxProtocol
{
public:
+ /**
+ Default constructor.
+ */
+ wxHTTP();
+
+ /**
+ Destructor will close the connection if connected.
+ */
+ virtual ~wxHTTP();
+
//@{
/**
Connect to the HTTP server.
//@}
/**
- Returns the data attached with a field whose name is specified by @e header.
+ Returns the data attached with a field whose name is specified by @a header.
If the field doesn't exist, it will return an empty string and not a @NULL string.
@note
Please refer to RFC 2616 for the list of responses.
*/
- int GetResponse();
+ int GetResponse() const;
/**
It sets data of a field to be sent during the next request to the HTTP server.
- The field name is specified by @a header and the content by @e h_data.
+ The field name is specified by @a header and the content by @a h_data.
This is a low level function and it assumes that you know what you are doing.
*/
void SetHeader(const wxString& header, const wxString& h_data);
Represents a protocol for use with wxURL.
+ Note that you may want to change the default time-out for HTTP/FTP connections
+ and network operations (using SetDefaultTimeout()) since the default time-out
+ value is quite long (60 seconds).
+
@library{wxnet}
@category{net}
/**
Returns the type of the content of the last opened stream. It is a mime-type.
+ May be an empty string if the content-type is unknown.
*/
- virtual wxString GetContentType();
+ virtual wxString GetContentType() const;
/**
Returns the last occurred error.
@see wxProtocolError
*/
- virtual wxProtocolError GetError() = 0;
+ virtual wxProtocolError GetError() const;
/**
Creates a new input stream on the specified path.
bool Reconnect();
/**
- Sets the authentication password. It is mainly useful when FTP is used.
+ Sets the authentication password.
*/
virtual void SetPassword(const wxString& user);
/**
- Sets the authentication user. It is mainly useful when FTP is used.
+ Sets the authentication user.
*/
virtual void SetUser(const wxString& user);
+
+ /**
+ Sets a new default timeout for the network operations.
+
+ The default timeout is 60 seconds.
+
+ @see wxSocketBase::SetTimeout
+ */
+ void SetDefaultTimeout(wxUint32 Value);
};
wxFTP::wxFTP()
{
- m_lastError = wxPROTO_NOERR;
m_streaming = false;
m_currentTransfermode = NONE;
- m_user = wxT("anonymous");
- m_passwd << wxGetUserId() << wxT('@') << wxGetFullHostName();
+ m_username = wxT("anonymous");
+ m_password << wxGetUserId() << wxT('@') << wxGetFullHostName();
SetNotify(0);
SetFlags(wxSOCKET_NOWAIT);
m_bPassive = true;
- SetDefaultTimeout(60); // Default is Sixty Seconds
m_bEncounteredError = false;
}
return false;
}
- if ( !m_user )
+ if ( !m_username )
{
m_lastError = wxPROTO_CONNERR;
return false;
}
wxString command;
- command.Printf(wxT("USER %s"), m_user.c_str());
+ command.Printf(wxT("USER %s"), m_username.c_str());
char rc = SendCommand(command);
if ( rc == '2' )
{
// 230 return: user accepted without password
+ m_lastError = wxPROTO_NOERR;
return true;
}
if ( rc != '3' )
{
+ m_lastError = wxPROTO_CONNERR;
Close();
return false;
}
- command.Printf(wxT("PASS %s"), m_passwd.c_str());
+ command.Printf(wxT("PASS %s"), m_password.c_str());
if ( !CheckCommand(command, '2') )
{
+ m_lastError = wxPROTO_CONNERR;
Close();
return false;
}
+ m_lastError = wxPROTO_NOERR;
return true;
}
{
if ( !CheckCommand(wxT("QUIT"), '2') )
{
+ m_lastError = wxPROTO_CONNERR;
wxLogDebug(_T("Failed to close connection gracefully."));
}
}
}
else
{
+ m_lastError = wxPROTO_NOERR;
sock = sockSrv->Accept(true);
delete sockSrv;
}
return CheckResult('2');
}
-void wxFTP::SetDefaultTimeout(wxUint32 Value)
-{
- m_uiDefaultTimeout = Value;
- SetTimeout(Value); // sets it for this socket
-}
// ----------------------------------------------------------------------------
// Send command to FTP server
wxLogTrace(FTP_TRACE_MASK, _T("==> %s"), cmd.c_str());
#endif // __WXDEBUG__
+ m_lastError = wxPROTO_NOERR;
return GetResult();
}
return 0;
}
+ else
+ m_lastError = wxPROTO_NOERR;
// if we got here we must have a non empty code string
return (char)code[0u];
if ( !CheckCommand(fullcmd, '2') )
{
wxLogDebug(_T("FTP command '%s' failed."), fullcmd.c_str());
+ m_lastError = wxPROTO_NETERR;
return false;
}
+ m_lastError = wxPROTO_NOERR;
return true;
}
}
else
{
+ m_lastError = wxPROTO_PROTERR;
wxLogDebug(_T("FTP PWD command failed."));
}
return NULL;
}
+ m_lastError = wxPROTO_NOERR;
sockSrv->Notify(false); // Don't send any events
return sockSrv;
}
{
if ( !DoSimpleCommand(_T("PASV")) )
{
+ m_lastError = wxPROTO_PROTERR;
wxLogError(_("The FTP server doesn't support passive mode."));
return NULL;
}
wxSocketClient *client = new wxSocketClient();
if ( !client->Connect(addr) )
{
+ m_lastError = wxPROTO_CONNERR;
delete client;
return NULL;
}
client->Notify(false);
+ m_lastError = wxPROTO_NOERR;
return client;
}
wxInputStream *wxFTP::GetInputStream(const wxString& path)
{
if ( ( m_currentTransfermode == NONE ) && !SetTransferMode(BINARY) )
+ {
+ m_lastError = wxPROTO_CONNERR;
return NULL;
+ }
wxSocketBase *sock = GetPort();
sock = AcceptIfActive(sock);
if ( !sock )
+ {
+ m_lastError = wxPROTO_CONNERR;
return NULL;
+ }
sock->SetFlags(wxSOCKET_WAITALL);
wxInputFTPStream *in_stream = new wxInputFTPStream(this, sock);
+ m_lastError = wxPROTO_NOERR;
return in_stream;
}
wxOutputStream *wxFTP::GetOutputStream(const wxString& path)
{
if ( ( m_currentTransfermode == NONE ) && !SetTransferMode(BINARY) )
+ {
+ m_lastError = wxPROTO_CONNERR;
return NULL;
+ }
wxSocketBase *sock = GetPort();
m_streaming = true;
+ m_lastError = wxPROTO_NOERR;
return new wxOutputFTPStream(this, sock);
}
bool details)
{
wxSocketBase *sock = GetPort();
- if (!sock)
+ if (!sock) {
+ m_lastError = wxPROTO_NETERR;
return false;
+ }
// NLST : List of Filenames (including Directory's !)
// LIST : depending on BS of FTP-Server
}
sock = AcceptIfActive(sock);
- if ( !sock )
+ if ( !sock ) {
+ m_lastError = wxPROTO_CONNERR;
return false;
+ }
files.Empty();
while (ReadLine(sock, line) == wxPROTO_NOERR )
delete sock;
// the file list should be terminated by "226 Transfer complete""
+ m_lastError = wxPROTO_NOERR;
return CheckResult('2');
}
#include "wx/sckstrm.h"
#include "wx/thread.h"
+
+// ----------------------------------------------------------------------------
+// wxHTTP
+// ----------------------------------------------------------------------------
+
IMPLEMENT_DYNAMIC_CLASS(wxHTTP, wxProtocol)
IMPLEMENT_PROTOCOL(wxHTTP, wxT("http"), wxT("80"), true)
void wxHTTP::ClearHeaders()
{
- m_headers.clear();
+ m_headers.clear();
}
-wxString wxHTTP::GetContentType()
+wxString wxHTTP::GetContentType() const
{
return GetHeader(wxT("Content-Type"));
}
for ( ;; )
{
- m_perr = ReadLine(this, line);
- if (m_perr != wxPROTO_NOERR)
+ m_lastError = ReadLine(this, line);
+ if (m_lastError != wxPROTO_NOERR)
return false;
if (line.length() == 0)
if (!addr->Hostname(host)) {
delete m_addr;
m_addr = NULL;
- m_perr = wxPROTO_NETERR;
+ m_lastError = wxPROTO_NETERR;
return false;
}
SetHeader(wxT("Host"), host);
+ m_lastError = wxPROTO_NOERR;
return true;
}
if (ipv4addr)
SetHeader(wxT("Host"), ipv4addr->OrigHostname());
+ m_lastError = wxPROTO_NOERR;
return true;
}
}
wxString tmp_str;
- m_perr = ReadLine(this, tmp_str);
- if (m_perr != wxPROTO_NOERR) {
+ m_lastError = ReadLine(this, tmp_str);
+ if (m_lastError != wxPROTO_NOERR) {
RestoreState();
return false;
}
if (!tmp_str.Contains(wxT("HTTP/"))) {
// TODO: support HTTP v0.9 which can have no header.
// FIXME: tmp_str is not put back in the in-queue of the socket.
+ m_lastError = wxPROTO_NOERR;
SetHeader(wxT("Content-Length"), wxT("-1"));
SetHeader(wxT("Content-Type"), wxT("none/none"));
RestoreState();
break;
default:
- m_perr = wxPROTO_NOFILE;
+ m_lastError = wxPROTO_NOFILE;
RestoreState();
return false;
}
+ m_lastError = wxPROTO_NOERR;
ret_value = ParseHeaders();
RestoreState();
return ret_value;
}
+bool wxHTTP::Abort(void)
+{
+ return wxSocketClient::Close();
+}
+
+// ----------------------------------------------------------------------------
+// wxHTTPStream and wxHTTP::GetInputStream
+// ----------------------------------------------------------------------------
+
class wxHTTPStream : public wxSocketInputStream
{
public:
// which is equivalent to getting a READ_ERROR, for clients however this
// must be translated into EOF, as it is the expected way of signalling
// end end of the content
- m_lasterror = wxSTREAM_EOF ;
+ m_lasterror = wxSTREAM_EOF;
}
return ret;
}
-bool wxHTTP::Abort(void)
-{
- return wxSocketClient::Close();
-}
-
wxInputStream *wxHTTP::GetInputStream(const wxString& path)
{
wxHTTPStream *inp_stream;
wxString new_path;
- m_perr = wxPROTO_CONNERR;
+ m_lastError = wxPROTO_CONNERR; // all following returns share this type of error
if (!m_addr)
return NULL;
Notify(false);
SetFlags(wxSOCKET_BLOCK | wxSOCKET_WAITALL);
+ // no error; reset m_lastError
+ m_lastError = wxPROTO_NOERR;
return inp_stream;
}
#include <stdlib.h>
-/////////////////////////////////////////////////////////////////
+// ----------------------------------------------------------------------------
// wxProtoInfo
-/////////////////////////////////////////////////////////////////
-
-/*
- * --------------------------------------------------------------
- * --------- wxProtoInfo CONSTRUCTOR ----------------------------
- * --------------------------------------------------------------
- */
+// ----------------------------------------------------------------------------
wxProtoInfo::wxProtoInfo(const wxChar *name, const wxChar *serv,
const bool need_host1, wxClassInfo *info)
#endif
}
-/////////////////////////////////////////////////////////////////
-// wxProtocol ///////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// wxProtocol
+// ----------------------------------------------------------------------------
#if wxUSE_SOCKETS
IMPLEMENT_ABSTRACT_CLASS(wxProtocol, wxSocketClient)
: wxSocketClient()
#endif
{
+ m_lastError = wxPROTO_NOERR;
+ SetDefaultTimeout(60); // default timeout is 60 seconds
}
#if wxUSE_SOCKETS
return true;
}
+void wxProtocol::SetDefaultTimeout(wxUint32 Value)
+{
+ m_uiDefaultTimeout = Value;
+#if wxUSE_SOCKETS
+ wxSocketBase::SetTimeout(Value); // sets it for this socket
+#endif
+}
+
+
// ----------------------------------------------------------------------------
// Read a line from socket
// ----------------------------------------------------------------------------
#include "wx/wfstream.h"
#include "wx/protocol/file.h"
+
+// ----------------------------------------------------------------------------
+// wxFileProto
+// ----------------------------------------------------------------------------
+
IMPLEMENT_DYNAMIC_CLASS(wxFileProto, wxProtocol)
IMPLEMENT_PROTOCOL(wxFileProto, wxT("file"), NULL, false)
wxFileProto::wxFileProto()
: wxProtocol()
{
- m_error = wxPROTO_NOERR;
}
wxFileProto::~wxFileProto()
wxFileInputStream *retval = new wxFileInputStream(wxURI::Unescape(path));
if ( retval->Ok() )
{
- m_error = wxPROTO_NOERR;
-
+ m_lastError = wxPROTO_NOERR;
return retval;
}
- m_error = wxPROTO_NOFILE;
+ m_lastError = wxPROTO_NOFILE;
delete retval;
return NULL;