// -*- c++ -*- ////////////////////////////////////////////////////////////////
-// Name: unix/dialup.cpp
-// Purpose: Network related wxWindows classes and functions
-// Author: Karsten Ballüder
+// Name: src/unix/dialup.cpp
+// Purpose: Network related wxWidgets classes and functions
+// Author: Karsten Ballüder
// Modified by:
// Created: 03.10.99
// RCS-ID: $Id$
-// Copyright: (c) Karsten Ballüder
+// Copyright: (c) Karsten Ballüder
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
-#include "wx/setup.h"
-
-#ifdef __GNUG__
-# pragma implementation "dialup.h"
-#endif
+// for compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
#if wxUSE_DIALUP_MANAGER
+#include "wx/dialup.h"
+
#ifndef WX_PRECOMP
-# include "wx/defs.h"
+ #include "wx/string.h"
+ #include "wx/intl.h"
+ #include "wx/log.h"
+ #include "wx/event.h"
+ #include "wx/app.h"
+ #include "wx/utils.h"
+ #include "wx/timer.h"
#endif // !PCH
-#include "wx/string.h"
-#include "wx/event.h"
-#include "wx/dialup.h"
-#include "wx/timer.h"
-#include "wx/filefn.h"
-#include "wx/utils.h"
-#include "wx/log.h"
+#include "wx/filename.h"
#include "wx/ffile.h"
#include "wx/process.h"
-#include "wx/intl.h"
-#include "wx/app.h"
-#include "wx/wxchar.h"
+#include "wx/crt.h"
#include <stdlib.h>
#include <arpa/inet.h>
#include <errno.h>
-DEFINE_EVENT_TYPE(wxEVT_DIALUP_CONNECTED)
-DEFINE_EVENT_TYPE(wxEVT_DIALUP_DISCONNECTED)
+wxDEFINE_EVENT( wxEVT_DIALUP_CONNECTED, wxDialUpEvent );
+wxDEFINE_EVENT( wxEVT_DIALUP_DISCONNECTED, wxDialUpEvent );
// ----------------------------------------------------------------------------
// A class which groups functions dealing with connecting to the network from a
{
public:
wxDialUpManagerImpl();
- ~wxDialUpManagerImpl();
+ virtual ~wxDialUpManagerImpl();
/** Could the dialup manager be initialized correctly? If this function
- returns FALSE, no other functions will work neither, so it's a good idea
+ returns false, no other functions will work neither, so it's a good idea
to call this function and check its result before calling any other
wxDialUpManager methods.
*/
virtual bool IsOk() const
- { return TRUE; }
+ { return true; }
/** The simplest way to initiate a dial up: this function dials the given
ISP (exact meaning of the parameter depends on the platform), returns
- TRUE on success or FALSE on failure and logs the appropriate error
+ true on success or false on failure and logs the appropriate error
message in the latter case.
@param nameOfISP optional paramater for dial program
@param username unused
// Hang up the currently active dial up connection.
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
// the "well-known host" (as specified by SetWellKnownHost) is reachable
virtual bool IsOnline() const
// do we have a constant net connection?
virtual bool IsAlwaysOnline() const;
- // returns TRUE if (async) dialing is in progress
+ // returns true if (async) dialing is in progress
virtual bool IsDialing() const
{ return m_DialProcess != NULL; }
- // cancel dialing the number initiated with Dial(async = TRUE)
+ // cancel dialing the number initiated with Dial(async = true)
// NB: this won't result in DISCONNECTED event being sent
virtual bool CancelDialing();
// so, in general, the user should be allowed to override it. This function
// allows to forcefully set the online status - whatever our internal
// algorithm may think about it.
- virtual void SetOnlineStatus(bool isOnline = TRUE)
+ virtual void SetOnlineStatus(bool isOnline = true)
{ m_IsOnline = isOnline ? Net_Connected : Net_No; }
// set misc wxDialUpManager options
// Windows, the notification about the change of connection status is
// instantenous.
//
- // Returns FALSE if couldn't set up automatic check for online status.
+ // Returns false if couldn't set up automatic check for online status.
virtual bool EnableAutoCheckOnlineStatus(size_t nSeconds);
// disable automatic check for connection status change - notice that the
friend class wxDialProcess;
// determine status
- void CheckStatus(bool fromAsync = FALSE) const;
+ void CheckStatus(bool fromAsync = false) const;
// real status check
void CheckStatusInternal();
{
public:
AutoCheckTimer(wxDialUpManagerImpl *dupman)
- {
- m_dupman = dupman;
- m_started = FALSE;
- }
-
- virtual bool Start( int millisecs = -1, bool WXUNUSED(one_shot) = FALSE )
- { m_started = TRUE; return wxTimer::Start(millisecs, FALSE); }
+ {
+ m_dupman = dupman;
+ }
virtual void Notify()
- { wxLogTrace(wxT("Checking dial up network status.")); m_dupman->CheckStatus(); }
+ {
+ wxLogTrace(wxT("dialup"), wxT("Checking dial up network status."));
+
+ m_dupman->CheckStatus();
+ }
- virtual void Stop()
- { if ( m_started ) wxTimer::Stop(); }
public:
- bool m_started;
wxDialUpManagerImpl *m_dupman;
};
if(m_DupMan)
{
m_DupMan->m_DialProcess = NULL;
- m_DupMan->CheckStatus(TRUE);
+ m_DupMan->CheckStatus(true);
}
}
private:
m_BeaconPort = 80;
#ifdef __SGI__
- m_ConnectCommand = _T("/usr/etc/ppp");
+ m_ConnectCommand = wxT("/usr/etc/ppp");
#elif defined(__LINUX__)
// default values for Debian/GNU linux
- m_ConnectCommand = _T("pon");
- m_HangUpCommand = _T("poff");
+ m_ConnectCommand = wxT("pon");
+ m_HangUpCommand = wxT("poff");
#endif
- wxChar * dial = wxGetenv(_T("WXDIALUP_DIALCMD"));
- wxChar * hup = wxGetenv(_T("WXDIALUP_HUPCMD"));
+ wxChar * dial = wxGetenv(wxT("WXDIALUP_DIALCMD"));
+ wxChar * hup = wxGetenv(wxT("WXDIALUP_HUPCMD"));
SetConnectCommand(dial ? wxString(dial) : m_ConnectCommand,
hup ? wxString(hup) : m_HangUpCommand);
}
const wxString & WXUNUSED(password),
bool async)
{
- if(m_IsOnline == Net_Connected)
- return FALSE;
- m_ISPname = isp;
- wxString cmd;
- if(m_ConnectCommand.Find(wxT("%s")))
- cmd.Printf(m_ConnectCommand,m_ISPname.c_str());
- else
- cmd = m_ConnectCommand;
+ if(m_IsOnline == Net_Connected)
+ return false;
+ m_ISPname = isp;
+ wxString cmd;
+ if(m_ConnectCommand.Find(wxT("%s")))
+ cmd.Printf(m_ConnectCommand,m_ISPname.c_str());
+ else
+ cmd = m_ConnectCommand;
- if ( async )
- {
- m_DialProcess = new wxDialProcess(this);
- m_DialPId = (int)wxExecute(cmd, FALSE, m_DialProcess);
- if(m_DialPId == 0)
- {
- delete m_DialProcess;
- m_DialProcess = NULL;
- return FALSE;
- }
- else
- return TRUE;
- }
- else
- return wxExecute(cmd, /* sync */ TRUE) == 0;
+ if ( async )
+ {
+ m_DialProcess = new wxDialProcess(this);
+ m_DialPId = (int)wxExecute(cmd, false, m_DialProcess);
+ if(m_DialPId == 0)
+ {
+ wxDELETE(m_DialProcess);
+ return false;
+ }
+ else
+ return true;
+ }
+ else
+ return wxExecute(cmd, /* sync */ true) == 0;
}
bool wxDialUpManagerImpl::HangUp()
{
- if(m_IsOnline == Net_No)
- return FALSE;
- if(IsDialing())
- {
- wxLogError(_("Already dialling ISP."));
- return FALSE;
- }
- wxString cmd;
- if(m_HangUpCommand.Find(wxT("%s")))
- cmd.Printf(m_HangUpCommand,m_ISPname.c_str(), m_DialProcess);
- else
- cmd = m_HangUpCommand;
- return wxExecute(cmd, /* sync */ TRUE) == 0;
+ if(m_IsOnline == Net_No)
+ return false;
+ if(IsDialing())
+ {
+ wxLogError(_("Already dialling ISP."));
+ return false;
+ }
+ wxString cmd;
+ if(m_HangUpCommand.Find(wxT("%s")))
+ cmd.Printf(m_HangUpCommand,m_ISPname.c_str(), m_DialProcess);
+ else
+ cmd = m_HangUpCommand;
+ return wxExecute(cmd, /* sync */ true) == 0;
}
bool wxDialUpManagerImpl::CancelDialing()
{
if(! IsDialing())
- return FALSE;
+ return false;
return kill(m_DialPId, SIGTERM) > 0;
}
bool rc = m_timer->Start(nSeconds*1000);
if(! rc)
{
- delete m_timer;
- m_timer = NULL;
+ wxDELETE(m_timer);
}
return rc;
}
if(m_timer != NULL)
{
m_timer->Stop();
- delete m_timer;
- m_timer = NULL;
+ wxDELETE(m_timer);
}
}
void wxDialUpManagerImpl::SetWellKnownHost(const wxString& hostname, int portno)
{
- if(hostname.Length() == 0)
+ if(hostname.length() == 0)
{
m_BeaconHost = WXDIALUP_MANAGER_DEFAULT_BEACONHOST;
m_BeaconPort = 80;
// does hostname contain a port number?
wxString port = hostname.After(wxT(':'));
- if(port.Length())
+ if(port.length())
{
m_BeaconHost = hostname.Before(wxT(':'));
m_BeaconPort = wxAtoi(port);
break;
default:
- wxFAIL_MSG(_T("Unexpected netDeviceType"));
+ wxFAIL_MSG(wxT("Unexpected netDeviceType"));
}
}
}
else // failed to connect
{
+#ifdef ENETUNREACH
if(errno == ENETUNREACH)
return Net_No; // network is unreachable
else
+#endif
return Net_Unknown; // connect failed, but don't know why
}
}
int netDevice = NetDevice_Unknown;
#ifdef __LINUX__
- if (wxFileExists(_T("/proc/net/route")))
+ if (wxFileExists(wxT("/proc/net/route")))
{
// cannot use wxFile::Length because file doesn't support seeking, so
// use stdio directly
wxDialUpManagerImpl::CheckIfconfig()
{
#ifdef __VMS
- m_CanUseIfconfig = 0;
- return -1;
+ m_CanUseIfconfig = 0;
+ return -1;
#else
- // assume that the test doesn't work
+ // assume that the test doesn't work
int netDevice = NetDevice_Unknown;
// first time check for ifconfig location
if ( m_CanUseIfconfig == -1 ) // unknown
{
- static const wxChar *ifconfigLocations[] =
+ static const wxChar *const ifconfigLocations[] =
{
- _T("/sbin"), // Linux, FreeBSD
- _T("/usr/sbin"), // SunOS, Solaris, AIX, HP-UX
- _T("/usr/etc"), // IRIX
+ wxT("/sbin"), // Linux, FreeBSD, Darwin
+ wxT("/usr/sbin"), // SunOS, Solaris, AIX, HP-UX
+ wxT("/usr/etc"), // IRIX
+ wxT("/etc"), // AIX 5
};
for ( size_t n = 0; n < WXSIZEOF(ifconfigLocations); n++ )
{
wxString path(ifconfigLocations[n]);
- path << _T("/ifconfig");
+ path << wxT("/ifconfig");
if ( wxFileExists(path) )
{
wxLogNull ln; // suppress all error messages
wxASSERT_MSG( m_IfconfigPath.length(),
- _T("can't use ifconfig if it wasn't found") );
+ wxT("can't use ifconfig if it wasn't found") );
- wxString tmpfile = wxGetTempFileName("_wxdialuptest");
- wxString cmd = "/bin/sh -c \'";
+ wxString tmpfile = wxFileName::CreateTempFileName( wxT("_wxdialuptest") );
+ wxString cmd = wxT("/bin/sh -c \'");
cmd << m_IfconfigPath;
-#if defined(__SOLARIS__) || defined (__SUNOS__)
+#if defined(__AIX__) || \
+ defined(__NETBSD__) || \
+ defined(__OSF__) || \
+ defined(__SOLARIS__) || defined (__SUNOS__)
// need to add -a flag
- cmd << " -a";
+ cmd << wxT(" -a");
#elif defined(__LINUX__) || defined(__SGI__)
// nothing to be added to ifconfig
-#elif defined(__FREEBSD__) || defined(__WXMAC__)
+#elif defined(__FREEBSD__) || defined(__DARWIN__) || defined(__QNX__)
// add -l flag
- cmd << " -l";
+ cmd << wxT(" -l");
#elif defined(__HPUX__)
// VZ: a wild guess (but without it, ifconfig fails completely)
- cmd << _T(" ppp0");
+ cmd << wxT(" ppp0");
#else
-# pragma warning "No ifconfig information for this OS."
- m_CanUseIfconfig = 0;
+ #if defined(__GNUG__)
+ #warning "No ifconfig information for this OS."
+ #else
+ #pragma warning "No ifconfig information for this OS."
+ #endif
+
+ m_CanUseIfconfig = 0;
return -1;
#endif
- cmd << " >" << tmpfile << '\'';
+ cmd << wxT(" >") << tmpfile << wxT('\'');
/* I tried to add an option to wxExecute() to not close stdout,
so we could let ifconfig write directly to the tmpfile, but
- this does not work. That should be faster, as it doesn´t call
+ this does not work. That should be faster, as it doesn't call
the shell first. I have no idea why. :-( (KB) */
- if ( wxExecute(cmd,TRUE /* sync */) == 0 )
+ if ( wxExecute(cmd,true /* sync */) == 0 )
{
m_CanUseIfconfig = 1;
wxFFile file;
{
// FIXME shouldn't we grep for "^ppp"? (VZ)
- bool hasModem = FALSE,
- hasLAN = FALSE;
+ bool hasModem = false,
+ hasLAN = false;
#if defined(__SOLARIS__) || defined (__SUNOS__)
// dialup device under SunOS/Solaris
- hasModem = strstr(output,"ipdptp") != (char *)NULL;
- hasLAN = strstr(output, "hme") != (char *)NULL;
-#elif defined(__LINUX__) || defined (__FREEBSD__)
- hasModem = strstr(output,"ppp") // ppp
- || strstr(output,"sl") // slip
- || strstr(output,"pl"); // plip
- hasLAN = strstr(output, "eth") != NULL;
+ hasModem = strstr(output.fn_str(),"ipdptp") != NULL;
+ hasLAN = strstr(output.fn_str(), "hme") != NULL;
+#elif defined(__LINUX__) || defined (__FREEBSD__) || defined (__QNX__)
+ hasModem = strstr(output.fn_str(),"ppp") // ppp
+ || strstr(output.fn_str(),"sl") // slip
+ || strstr(output.fn_str(),"pl"); // plip
+ hasLAN = strstr(output.fn_str(), "eth") != NULL;
#elif defined(__SGI__) // IRIX
- hasModem = strstr(output, "ppp") != NULL; // PPP
+ hasModem = strstr(output.fn_str(), "ppp") != NULL; // PPP
#elif defined(__HPUX__)
// if could run ifconfig on interface, then it exists
- hasModem = TRUE;
+ hasModem = true;
#endif
netDevice = NetDevice_None;
}
else // could not run ifconfig correctly
{
- m_CanUseIfconfig = 0; // don´t try again
+ m_CanUseIfconfig = 0; // don't try again
}
(void) wxRemoveFile(tmpfile);
wxDialUpManagerImpl::NetConnection wxDialUpManagerImpl::CheckPing()
{
- // First time check for ping location. We only use the variant
- // which does not take arguments, a la GNU.
- if(m_CanUsePing == -1) // unknown
- {
+ // First time check for ping location. We only use the variant
+ // which does not take arguments, a la GNU.
+ if(m_CanUsePing == -1) // unknown
+ {
#ifdef __VMS
- if(wxFileExists("SYS$SYSTEM:TCPIP$PING.EXE"))
- m_PingPath = "$SYS$SYSTEM:TCPIP$PING";
+ if (wxFileExists( wxT("SYS$SYSTEM:TCPIP$PING.EXE") ))
+ m_PingPath = wxT("$SYS$SYSTEM:TCPIP$PING");
+#elif defined(__AIX__)
+ m_PingPath = wxT("/etc/ping");
+#elif defined(__SGI__)
+ m_PingPath = wxT("/usr/etc/ping");
#else
- if(wxFileExists("/bin/ping"))
- m_PingPath = "/bin/ping";
- else if(wxFileExists("/usr/sbin/ping"))
- m_PingPath = "/usr/sbin/ping";
+ if (wxFileExists( wxT("/bin/ping") ))
+ m_PingPath = wxT("/bin/ping");
+ else if (wxFileExists( wxT("/usr/sbin/ping") ))
+ m_PingPath = wxT("/usr/sbin/ping");
#endif
- if(! m_PingPath)
- {
- m_CanUsePing = 0;
- }
- }
+ if (!m_PingPath)
+ {
+ m_CanUsePing = 0;
+ }
+ }
- if(! m_CanUsePing)
- {
+ if(! m_CanUsePing)
+ {
// we didn't find ping
return Net_Unknown;
- }
+ }
- wxLogNull ln; // suppress all error messages
- wxASSERT(m_PingPath.length());
- wxString cmd;
- cmd << m_PingPath << ' ';
+ wxLogNull ln; // suppress all error messages
+ wxASSERT(m_PingPath.length());
+ wxString cmd;
+ cmd << m_PingPath << wxT(' ');
#if defined(__SOLARIS__) || defined (__SUNOS__)
- // nothing to add to ping command
-#elif defined(__LINUX__) || defined ( __FREEBSD__) || defined(__WXMAC__) || defined( __VMS )
- cmd << "-c 1 "; // only ping once
+ // nothing to add to ping command
+#elif defined(__AIX__) || \
+ defined (__BSD__) || \
+ defined(__LINUX__) || \
+ defined(__OSF__) || \
+ defined(__SGI__) || \
+ defined(__VMS) || \
+ defined(__QNX__)
+ cmd << wxT("-c 1 "); // only ping once
#elif defined(__HPUX__)
- cmd << "64 1 "; // only ping once (need also specify the packet size)
+ cmd << wxT("64 1 "); // only ping once (need also specify the packet size)
#else
-# pragma warning "No Ping information for this OS."
- m_CanUsePing = 0;
- return Net_Unknown;
+ #if defined(__GNUG__)
+ #warning "No Ping information for this OS."
+ #else
+ #pragma warning "No Ping information for this OS."
+ #endif
+
+ m_CanUsePing = 0;
+ return Net_Unknown;
#endif
- cmd << m_BeaconHost;
- if(wxExecute(cmd, TRUE /* sync */) == 0)
- return Net_Connected;
- else
- return Net_No;
+ cmd << m_BeaconHost;
+ if(wxExecute(cmd, true /* sync */) == 0)
+ return Net_Connected;
+ else
+ return Net_No;
}
/* static */