1. Win9x support + async dialing + many more for wxDialUpManager
2. renamed files from net.h/cpp to dialup.h/cpp git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3802 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: wx/net.h
|
// Name: wx/dialup.h
|
||||||
// Purpose: Network related wxWindows classes and functions
|
// Purpose: Network related wxWindows classes and functions
|
||||||
// Author: Vadim Zeitlin
|
// Author: Vadim Zeitlin
|
||||||
// Modified by:
|
// Modified by:
|
||||||
@@ -14,6 +14,14 @@
|
|||||||
|
|
||||||
#if wxUSE_DIALUP_MANAGER
|
#if wxUSE_DIALUP_MANAGER
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// constants
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern const wxChar *wxEmptyString;
|
||||||
|
|
||||||
|
#define WXDIALUP_MANAGER_DEFAULT_BEACONHOST _T("www.yahoo.com")
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// A class which groups functions dealing with connecting to the network from a
|
// A class which groups functions dealing with connecting to the network from a
|
||||||
// workstation using dial-up access to the net. There is at most one instance
|
// workstation using dial-up access to the net. There is at most one instance
|
||||||
@@ -24,12 +32,8 @@
|
|||||||
*
|
*
|
||||||
* 1. more configurability for Unix: i.e. how to initiate the connection, how
|
* 1. more configurability for Unix: i.e. how to initiate the connection, how
|
||||||
* to check for online status, &c.
|
* to check for online status, &c.
|
||||||
* 2. add a "long Dial(long connectionId = -1)" function which asks the user
|
* 2. a function to enumerate all connections (ISPs) and show a dialog in
|
||||||
* about which connection to dial (this may be done using native dialogs
|
* Dial() allowing to choose between them if no ISP given
|
||||||
* under NT, need generic dialogs for all others) and returns the identifier
|
|
||||||
* of the selected connection (it's opaque to the application) - it may be
|
|
||||||
* reused later to dial the same connection later (or use strings instead of
|
|
||||||
* longs may be?)
|
|
||||||
* 3. add an async version of dialing functions which notify the caller about
|
* 3. add an async version of dialing functions which notify the caller about
|
||||||
* the progress (or may be even start another thread to monitor it)
|
* the progress (or may be even start another thread to monitor it)
|
||||||
* 4. the static creation/accessor functions are not MT-safe - but is this
|
* 4. the static creation/accessor functions are not MT-safe - but is this
|
||||||
@@ -37,8 +41,6 @@
|
|||||||
* main thread?
|
* main thread?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define WXDIALUP_MANAGER_DEFAULT_BEACONHOST "www.yahoo.com"
|
|
||||||
|
|
||||||
class WXDLLEXPORT wxDialUpManager
|
class WXDLLEXPORT wxDialUpManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -59,13 +61,24 @@ public:
|
|||||||
// operations
|
// operations
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
// the simplest way to initiate a dial up: this function dials the given
|
// dial the given ISP, use username and password to authentificate
|
||||||
// ISP (exact meaning of the parameter depends on the platform), returns
|
//
|
||||||
// TRUE on success or FALSE on failure and logs the appropriate error
|
// if async parameter is FALSE, the function waits until the end of dialing
|
||||||
// message in the latter case.
|
// and returns TRUE upon successful completion.
|
||||||
virtual bool Dial(const wxString& nameOfISP = "",
|
// if async is TRUE, the function only initiates the connection and returns
|
||||||
const wxString& username = "",
|
// immediately - the result is reported via events (an event is sent
|
||||||
const wxString& password = "") = 0;
|
// anyhow, but if dialing failed it will be a DISCONNECTED one)
|
||||||
|
virtual bool Dial(const wxString& nameOfISP = wxEmptyString,
|
||||||
|
const wxString& username = wxEmptyString,
|
||||||
|
const wxString& password = wxEmptyString,
|
||||||
|
bool async = TRUE) = 0;
|
||||||
|
|
||||||
|
// returns TRUE if (async) dialing is in progress
|
||||||
|
virtual bool IsDialing() const = 0;
|
||||||
|
|
||||||
|
// cancel dialing the number initiated with Dial(async = TRUE)
|
||||||
|
// NB: this won't result in DISCONNECTED event being sent
|
||||||
|
virtual bool CancelDialing() = 0;
|
||||||
|
|
||||||
// hang up the currently active dial up connection
|
// hang up the currently active dial up connection
|
||||||
virtual bool HangUp() = 0;
|
virtual bool HangUp() = 0;
|
||||||
@@ -100,17 +113,20 @@ public:
|
|||||||
// wxEVT_DIALUP_XXX events won't be sent any more neither.
|
// wxEVT_DIALUP_XXX events won't be sent any more neither.
|
||||||
virtual void DisableAutoCheckOnlineStatus() = 0;
|
virtual void DisableAutoCheckOnlineStatus() = 0;
|
||||||
|
|
||||||
|
// additional Unix-only configuration
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
// under Unix, the value of well-known host is used to check whether we're
|
// under Unix, the value of well-known host is used to check whether we're
|
||||||
// connected to the internet. It's unused under Windows, but this function
|
// connected to the internet. It's unused under Windows, but this function
|
||||||
// is always safe to call. The default value is www.yahoo.com.
|
// is always safe to call. The default value is www.yahoo.com.
|
||||||
virtual void SetWellKnownHost(const wxString& hostname,
|
virtual void SetWellKnownHost(const wxString& hostname,
|
||||||
int portno = 80) = 0;
|
int portno = 80) = 0;
|
||||||
/** Sets the commands to start up the network and to hang up
|
|
||||||
again. Used by the Unix implementations only.
|
// Sets the commands to start up the network and to hang up again. Used by
|
||||||
*/
|
// the Unix implementations only.
|
||||||
virtual void SetConnectCommand(const wxString &command = "/usr/bin/pon",
|
virtual void
|
||||||
const wxString &hupcmd = "/usr/bin/poff")
|
SetConnectCommand(const wxString& commandDial = _T("/usr/bin/pon"),
|
||||||
{ }
|
const wxString& commandHangup = _T("/usr/bin/poff")) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -121,14 +137,20 @@ public:
|
|||||||
class WXDLLEXPORT wxDialUpEvent : public wxEvent
|
class WXDLLEXPORT wxDialUpEvent : public wxEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDialUpEvent(bool isConnected) : wxEvent(isConnected)
|
wxDialUpEvent(bool isConnected, bool isOwnEvent) : wxEvent(isOwnEvent)
|
||||||
{
|
{
|
||||||
SetEventType(isConnected ? wxEVT_DIALUP_CONNECTED
|
SetEventType(isConnected ? wxEVT_DIALUP_CONNECTED
|
||||||
: wxEVT_DIALUP_DISCONNECTED);
|
: wxEVT_DIALUP_DISCONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this a CONNECTED or DISCONNECTED event?
|
// is this a CONNECTED or DISCONNECTED event?
|
||||||
bool IsConnectedEvent() const { return m_id != 0; }
|
bool IsConnectedEvent() const
|
||||||
|
{ return GetEventType() == wxEVT_DIALUP_CONNECTED; }
|
||||||
|
|
||||||
|
// does this event come from wxDialUpManager::Dial() or from some extrenal
|
||||||
|
// process (i.e. does it result from our own attempt to establish the
|
||||||
|
// connection)?
|
||||||
|
bool IsOwnEvent() const { return m_id != 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// the type of dialup event handler function
|
// the type of dialup event handler function
|
1061
src/msw/dialup.cpp
Normal file
1061
src/msw/dialup.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
// -*- c++ -*- ///////////////////////////////////////////////////////////////
|
// -*- c++ -*- ///////////////////////////////////////////////////////////////
|
||||||
// Name: unix/net.cpp
|
// Name: unix/dialup.cpp
|
||||||
// Purpose: Network related wxWindows classes and functions
|
// Purpose: Network related wxWindows classes and functions
|
||||||
// Author: Karsten Ballüder
|
// Author: Karsten Ballüder
|
||||||
// Modified by:
|
// Modified by:
|
||||||
@@ -89,11 +89,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual bool Dial(const wxString& nameOfISP,
|
virtual bool Dial(const wxString& nameOfISP,
|
||||||
const wxString& WXUNUSED(username),
|
const wxString& WXUNUSED(username),
|
||||||
const wxString& WXUNUSED(password));
|
const wxString& WXUNUSED(password),
|
||||||
|
bool async);
|
||||||
|
|
||||||
/// Hang up the currently active dial up connection.
|
/// Hang up the currently active dial up connection.
|
||||||
virtual bool HangUp();
|
virtual bool HangUp();
|
||||||
|
|
||||||
// returns TRUE if the computer is connected to the network: under Windows,
|
// returns TRUE if the computer is connected to the network: under Windows,
|
||||||
// this just means that a RAS connection exists, under Unix we check that
|
// this just means that a RAS connection exists, under Unix we check that
|
||||||
// the "well-known host" (as specified by SetWellKnownHost) is reachable
|
// the "well-known host" (as specified by SetWellKnownHost) is reachable
|
||||||
@@ -143,7 +144,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
/// -1: don´t know, 0 = no, 1 = yes
|
/// -1: don´t know, 0 = no, 1 = yes
|
||||||
int m_IsOnline;
|
int m_IsOnline;
|
||||||
|
|
||||||
/// Can we use ifconfig to list active devices?
|
/// Can we use ifconfig to list active devices?
|
||||||
int m_CanUseIfconfig;
|
int m_CanUseIfconfig;
|
||||||
/// The path to ifconfig
|
/// The path to ifconfig
|
||||||
@@ -197,7 +198,8 @@ public:
|
|||||||
bool
|
bool
|
||||||
wxDialUpManagerImpl::Dial(const wxString &isp,
|
wxDialUpManagerImpl::Dial(const wxString &isp,
|
||||||
const wxString & WXUNUSED(username),
|
const wxString & WXUNUSED(username),
|
||||||
const wxString & WXUNUSED(password))
|
const wxString & WXUNUSED(password),
|
||||||
|
bool async)
|
||||||
{
|
{
|
||||||
if(m_IsOnline == 1)
|
if(m_IsOnline == 1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -208,7 +210,15 @@ wxDialUpManagerImpl::Dial(const wxString &isp,
|
|||||||
cmd.Printf(m_ConnectCommand,m_ISPname.c_str());
|
cmd.Printf(m_ConnectCommand,m_ISPname.c_str());
|
||||||
else
|
else
|
||||||
cmd = m_ConnectCommand;
|
cmd = m_ConnectCommand;
|
||||||
return wxExecute(cmd, /* sync */ TRUE) == 0;
|
|
||||||
|
if ( async )
|
||||||
|
{
|
||||||
|
wxFAIL_MSG(_T("TODO"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return wxExecute(cmd, /* sync */ TRUE) == 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -297,7 +307,7 @@ wxDialUpManagerImpl::CheckStatus(void) const
|
|||||||
3. check /proc/net/dev on linux??
|
3. check /proc/net/dev on linux??
|
||||||
This method should be preferred, if possible. Need to do more
|
This method should be preferred, if possible. Need to do more
|
||||||
testing.
|
testing.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -319,7 +329,7 @@ wxDialUpManagerImpl::CheckStatusInternal(void)
|
|||||||
if(m_CanUseIfconfig != 0) // unknown or yes
|
if(m_CanUseIfconfig != 0) // unknown or yes
|
||||||
{
|
{
|
||||||
wxASSERT(m_IfconfigPath.length());
|
wxASSERT(m_IfconfigPath.length());
|
||||||
|
|
||||||
wxString tmpfile = wxGetTempFileName("_wxdialuptest");
|
wxString tmpfile = wxGetTempFileName("_wxdialuptest");
|
||||||
wxString cmd = m_IfconfigPath;
|
wxString cmd = m_IfconfigPath;
|
||||||
cmd << " >" << tmpfile;
|
cmd << " >" << tmpfile;
|
||||||
@@ -345,22 +355,22 @@ wxDialUpManagerImpl::CheckStatusInternal(void)
|
|||||||
// second method: try to connect to well known host:
|
// second method: try to connect to well known host:
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
struct sockaddr_in serv_addr;
|
struct sockaddr_in serv_addr;
|
||||||
int sockfd;
|
int sockfd;
|
||||||
|
|
||||||
m_IsOnline = 0; // assume false
|
m_IsOnline = 0; // assume false
|
||||||
if((hp = gethostbyname(m_BeaconHost)) == NULL)
|
if((hp = gethostbyname(m_BeaconHost)) == NULL)
|
||||||
return; // no DNS no net
|
return; // no DNS no net
|
||||||
|
|
||||||
serv_addr.sin_family = hp->h_addrtype;
|
serv_addr.sin_family = hp->h_addrtype;
|
||||||
memcpy(&serv_addr.sin_addr,hp->h_addr, hp->h_length);
|
memcpy(&serv_addr.sin_addr,hp->h_addr, hp->h_length);
|
||||||
serv_addr.sin_port = htons(m_BeaconPort);
|
serv_addr.sin_port = htons(m_BeaconPort);
|
||||||
if( ( sockfd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0)
|
if( ( sockfd = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0)
|
||||||
{
|
{
|
||||||
// sys_error("cannot create socket for gw");
|
// sys_error("cannot create socket for gw");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
|
if( connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
|
||||||
{
|
{
|
||||||
//sys_error("cannot connect to server");
|
//sys_error("cannot connect to server");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
Reference in New Issue
Block a user