summaryrefslogtreecommitdiff
authortille <tille>2003-05-24 23:34:09 (UTC)
committer tille <tille>2003-05-24 23:34:09 (UTC)
commitd1c32c127b4dabb716064a790da6be7c24975a92 (patch) (side-by-side diff)
treeaa8a7865d4cccbc696c534d8de3ef3b139777c34
parent58947769d80d49faaccac1703da0e66c90158957 (diff)
downloadopie-d1c32c127b4dabb716064a790da6be7c24975a92.zip
opie-d1c32c127b4dabb716064a790da6be7c24975a92.tar.gz
opie-d1c32c127b4dabb716064a790da6be7c24975a92.tar.bz2
pppd stuff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp229
-rw-r--r--noncore/settings/networksettings/ppp/modem.h6
-rw-r--r--noncore/settings/networksettings/ppp/pppdata.cpp134
-rw-r--r--noncore/settings/networksettings/ppp/pppdata.h35
-rw-r--r--noncore/settings/networksettings/ppp/pppmodule.cpp28
5 files changed, 330 insertions, 102 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
index cd5d21c..5139482 100644
--- a/noncore/settings/networksettings/ppp/modem.cpp
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -17,32 +17,44 @@
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <errno.h>
#include <stdlib.h>
+#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <setjmp.h>
#include <regex.h>
#include <qregexp.h>
#include <assert.h>
+#include <string.h>
+#ifdef HAVE_RESOLV_H
+# include <arpa/nameser.h>
+# include <resolv.h>
+#endif
+
+#ifndef _PATH_RESCONF
+#define _PATH_RESCONF "/etc/resolv.conf"
+#endif
+
+#define strlcpy strcpy
#include "auth.h"
#include "modem.h"
#include "pppdata.h"
//#include <klocale.h>
#define i18n QObject::tr
#define qError qDebug
//#include <kdebug.h>
//#include <config.h>
#define MY_ASSERT(x) if (!(x)) { \
qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \
exit(1); }
@@ -74,24 +86,26 @@ const char* pppdPath() {
return (pppdPath = buffer);
}
}
return pppdPath;
}
Modem::Modem()
{
if (Modem::modem != 0) return; //CORRECT?
modemfd = -1;
+ _pppdExitStatus = -1;
+ pppdPid = -1;
sn = 0L;
data_mode = false;
modem_is_locked = false;
lockfile[0] = '\0';
device = "/dev/modem";
modem = this;
}
Modem::~Modem() {
modem = 0;
}
@@ -746,64 +760,263 @@ bool Modem::createAuthFile(Auth method, const char *username, const char *passwo
return false;
// delete old file if any
unlink(oldName);
rename(authfile, oldName);
rename(newName, authfile);
return true;
}
+bool Modem::removeAuthFile(Auth method) {
+ const char *authfile, *oldName;
+
+ if(!(authfile = authFile(method)))
+ return false;
+ if(!(oldName = authFile(method, Old)))
+ return false;
+
+ if(access(oldName, F_OK) == 0) {
+ unlink(authfile);
+ return (rename(oldName, authfile) == 0);
+ } else
+ return false;
+}
+
+
bool Modem::setSecret(int method, const char* name, const char* password)
{
Auth auth;
if(method == AUTH_PAPCHAP)
return setSecret(AUTH_PAP, name, password) &&
setSecret(AUTH_CHAP, name, password);
switch(method) {
case AUTH_PAP:
auth = Modem::PAP;
break;
case AUTH_CHAP:
auth = Modem::CHAP;
break;
default:
return false;
}
return createAuthFile(auth, name, password);
}
-bool Modem::removeSecret(int)
+bool Modem::removeSecret(int method)
{
- return true;
+ Auth auth;
+
+ switch(method) {
+ case AUTH_PAP:
+ auth = Modem::PAP;
+ break;
+ case AUTH_CHAP:
+ auth = Modem::CHAP;
+ break;
+ default:
+ return false;
+ }
+ return removeAuthFile( auth );
}
-void Modem::killPPPDaemon()
+int checkForInterface()
{
+// I don't know if Linux needs more initialization to get the ioctl to
+// work, pppd seems to hint it does. But BSD doesn't, and the following
+// code should compile.
+#if (defined(HAVE_NET_IF_PPP_H) || defined(HAVE_LINUX_IF_PPP_H)) && !defined(__svr4__)
+ int s, ok;
+ struct ifreq ifr;
+ // extern char *no_ppp_msg;
+
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ return 1; /* can't tell */
+
+ strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
+ ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
+ close(s);
+
+ if (ok == -1) {
+// This is ifdef'd FreeBSD, because FreeBSD is the only BSD that supports
+// KLDs, the old LKM interface couldn't handle loading devices
+// dynamically, and thus can't load ppp support on the fly
+#ifdef __FreeBSD__
+ // If we failed to load ppp support and don't have it already.
+ if (kldload("if_ppp") == -1) {
+ return -1;
+ }
+ return 0;
+#else
+ return -1;
+#endif
+ }
+ return 0;
+#else
+// We attempt to use the SunOS/SysVr4 method and stat /dev/ppp
+ struct stat buf;
+
+ memset(&buf, 0, sizeof(buf));
+ return stat("/dev/ppp", &buf);
+#endif
}
-int Modem::pppdExitStatus()
-{
- return -1;
+bool Modem::execpppd(const char *arguments) {
+ char buf[MAX_CMDLEN];
+ char *args[MaxArgs];
+ pid_t pgrpid;
+
+ if(modemfd<0)
+ return false;
+
+ _pppdExitStatus = -1;
+
+ switch(pppdPid = fork())
+ {
+ case -1:
+ fprintf(stderr,"In parent: fork() failed\n");
+ return false;
+ break;
+
+ case 0:
+ // let's parse the arguments the user supplied into UNIX suitable form
+ // that is a list of pointers each pointing to exactly one word
+ strlcpy(buf, arguments);
+ parseargs(buf, args);
+ // become a session leader and let /dev/ttySx
+ // be the controlling terminal.
+ pgrpid = setsid();
+#ifdef TIOCSCTTY
+ if(ioctl(modemfd, TIOCSCTTY, 0)<0)
+ fprintf(stderr, "ioctl() failed.\n");
+#elif defined (TIOCSPGRP)
+ if(ioctl(modemfd, TIOCSPGRP, &pgrpid)<0)
+ fprintf(stderr, "ioctl() failed.\n");
+#endif
+ if(tcsetpgrp(modemfd, pgrpid)<0)
+ fprintf(stderr, "tcsetpgrp() failed.\n");
+
+ dup2(modemfd, 0);
+ dup2(modemfd, 1);
+
+ switch (checkForInterface()) {
+ case 1:
+ fprintf(stderr, "Cannot determine if kernel supports ppp.\n");
+ break;
+ case -1:
+ fprintf(stderr, "Kernel does not support ppp, oops.\n");
+ break;
+ case 0:
+ fprintf(stderr, "Kernel supports ppp alright.\n");
+ break;
+ }
+
+ execve(pppdPath(), args, 0L);
+ _exit(0);
+ break;
+
+ default:
+ qDebug("In parent: pppd pid %d\n",pppdPid);
+ close(modemfd);
+ modemfd = -1;
+ return true;
+ break;
+ }
+}
+
+
+bool Modem::killpppd() {
+ if(pppdPid > 0) {
+ qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid);
+ if(kill(pppdPid, SIGTERM) < 0) {
+ qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid);
+ if(kill(pppdPid, SIGKILL) < 0) {
+ qDebug("Error killing %d\n", pppdPid);
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+
+void Modem::parseargs(char* buf, char** args) {
+ int nargs = 0;
+ int quotes;
+
+ while(nargs < MaxArgs-1 && *buf != '\0') {
+
+ quotes = 0;
+
+ // Strip whitespace. Use nulls, so that the previous argument is
+ // terminated automatically.
+
+ while ((*buf == ' ' ) || (*buf == '\t' ) || (*buf == '\n' ) )
+ *buf++ = '\0';
+
+ // detect begin of quoted argument
+ if (*buf == '"' || *buf == '\'') {
+ quotes = *buf;
+ *buf++ = '\0';
+ }
+
+ // save the argument
+ if(*buf != '\0') {
+ *args++ = buf;
+ nargs++;
+ }
+
+ if (!quotes)
+ while ((*buf != '\0') && (*buf != '\n') &&
+ (*buf != '\t') && (*buf != ' '))
+ buf++;
+ else {
+ while ((*buf != '\0') && (*buf != quotes))
+ buf++;
+ *buf++ = '\0';
+ }
+ }
+
+ *args = 0L;
}
bool Modem::execPPPDaemon(const QString & arguments)
{
+ if(execpppd(arguments)==0) {
+ PPPData::data()->setpppdRunning(true);
return true;
+ } else
+ return false;
+}
+
+void Modem::killPPPDaemon()
+{
+ PPPData::data()->setpppdRunning(false);
+ killpppd();
+}
+
+int Modem::pppdExitStatus()
+{
+ return _pppdExitStatus;
}
int Modem::openResolv(int flags)
{
- return -1;
+ int fd;
+ if ((fd = open(_PATH_RESCONF, flags)) == -1) {
+ qDebug("error opening resolv.conf!");
+ fd = open(DEVNULL, O_RDONLY);
+ }
+ return fd;
}
bool Modem::setHostname(const QString & name)
{
- return true;
+ return sethostname(name, name.length()) == 0;
}
diff --git a/noncore/settings/networksettings/ppp/modem.h b/noncore/settings/networksettings/ppp/modem.h
index 052be4a..b494977 100644
--- a/noncore/settings/networksettings/ppp/modem.h
+++ b/noncore/settings/networksettings/ppp/modem.h
@@ -84,30 +84,36 @@ signals:
private slots:
void startNotifier();
void stopNotifier();
void readtty(int);
private:
enum { MaxPathLen = 30, MaxStrLen = 40, MaxArgs = 100 };
enum { Original=0x100, New=0x200, Old=0x400 } Version;
const char* authFile(Auth method, int version = Original );
bool createAuthFile(Auth method,const char *username,const char *password);
+ bool removeAuthFile(Auth method);
+ bool execpppd(const char *arguments);
+ bool killpppd();
+ void parseargs(char* buf, char** args);
void escape_to_command_mode();
int openLockfile(QString,int);
private:
QString device;
QString lockfile;
int modemfd;
+ int pppdPid;
+ int _pppdExitStatus;
QSocketNotifier *sn;
bool data_mode;
QString errmsg;
struct termios initial_tty;
struct termios tty;
bool modem_is_locked;
};
#endif
diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp
index 646facd..bb1c8ed 100644
--- a/noncore/settings/networksettings/ppp/pppdata.cpp
+++ b/noncore/settings/networksettings/ppp/pppdata.cpp
@@ -314,300 +314,300 @@ bool PPPData::pppdVersionMin(int ver, int mod, int patch) {
int PPPData::pppdTimeout() {
return readNumConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, PPPD_TIMEOUT);
}
void PPPData::setpppdTimeout(int n) {
writeConfig(GENERAL_GRP, PPPDTIMEOUT_KEY, n);
}
const QString PPPData::modemDevice() {
- return readConfig (MODEM_GRP, MODEMDEV_KEY, devices[DEV_DEFAULT]);
+ return readConfig (modemGroup(), MODEMDEV_KEY, devices[DEV_DEFAULT]);
}
void PPPData::setModemDevice(const QString &n) {
- writeConfig(MODEM_GRP, MODEMDEV_KEY, n);
+ writeConfig(modemGroup(), MODEMDEV_KEY, n);
}
const QString PPPData::flowcontrol() {
- return readConfig(MODEM_GRP, FLOWCONTROL_KEY, "CRTSCTS");
+ return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS");
}
void PPPData::setFlowcontrol(const QString &n) {
- writeConfig(MODEM_GRP, FLOWCONTROL_KEY, n);
+ writeConfig(modemGroup(), FLOWCONTROL_KEY, n);
}
const QString PPPData::speed() {
- QString s = readConfig(MODEM_GRP, SPEED_KEY, "57600");
+ QString s = readConfig(modemGroup(), SPEED_KEY, "57600");
// undo the damage of a bug in former versions. It left an empty Speed=
// entry in kppprc. kppp did set the serial port to 57600 as default but
// pppd wouldn't receive the speed via the command line.
if(s.toUInt() == 0)
s = "57600";
return s;
}
void PPPData::setSpeed(const QString &n) {
- writeConfig(MODEM_GRP, SPEED_KEY, n);
+ writeConfig(modemGroup(), SPEED_KEY, n);
}
#if 0
void PPPData::setUseCDLine(const int n) {
- writeConfig(MODEM_GRP,USECDLINE_KEY,n);
+ writeConfig(modemGroup(),USECDLINE_KEY,n);
}
int PPPData::UseCDLine() {
- return readNumConfig(MODEM_GRP,USECDLINE_KEY,0);
+ return readNumConfig(modemGroup(),USECDLINE_KEY,0);
}
#endif
const QString PPPData::modemEscapeStr() {
- return readConfig(MODEM_GRP,ESCAPESTR_KEY,"+++");
+ return readConfig(modemGroup(),ESCAPESTR_KEY,"+++");
}
void PPPData::setModemEscapeStr(const QString &n) {
- writeConfig(MODEM_GRP,ESCAPESTR_KEY,n);
+ writeConfig(modemGroup(),ESCAPESTR_KEY,n);
}
const QString PPPData::modemEscapeResp() {
- return readConfig(MODEM_GRP,ESCAPERESP_KEY,"OK");
+ return readConfig(modemGroup(),ESCAPERESP_KEY,"OK");
}
void PPPData::setModemEscapeResp(const QString &n) {
- writeConfig(MODEM_GRP,ESCAPERESP_KEY,n);
+ writeConfig(modemGroup(),ESCAPERESP_KEY,n);
}
int PPPData::modemEscapeGuardTime() {
- return readNumConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,50);
+ return readNumConfig(modemGroup(),ESCAPEGUARDTIME_KEY,50);
}
void PPPData::setModemEscapeGuardTime(int n) {
- writeConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,n);
+ writeConfig(modemGroup(),ESCAPEGUARDTIME_KEY,n);
}
bool PPPData::modemLockFile() {
- return readNumConfig(MODEM_GRP, LOCKFILE_KEY, 1);
+ return readNumConfig(modemGroup(), LOCKFILE_KEY, 1);
}
void PPPData::setModemLockFile(bool set) {
- writeConfig(MODEM_GRP, LOCKFILE_KEY, set);
+ writeConfig(modemGroup(), LOCKFILE_KEY, set);
}
int PPPData::modemTimeout() {
- return readNumConfig(MODEM_GRP, TIMEOUT_KEY, MODEM_TIMEOUT);
+ return readNumConfig(modemGroup(), TIMEOUT_KEY, MODEM_TIMEOUT);
}
void PPPData::setModemTimeout(int n) {
- writeConfig(MODEM_GRP, TIMEOUT_KEY, n);
+ writeConfig(modemGroup(), TIMEOUT_KEY, n);
}
int PPPData::modemToneDuration() {
- return readNumConfig(MODEM_GRP, TONEDURATION_KEY,MODEM_TONEDURATION);
+ return readNumConfig(modemGroup(), TONEDURATION_KEY,MODEM_TONEDURATION);
}
void PPPData::setModemToneDuration(int n) {
- writeConfig(MODEM_GRP, TONEDURATION_KEY, n);
+ writeConfig(modemGroup(), TONEDURATION_KEY, n);
}
int PPPData::busyWait() {
- return readNumConfig(MODEM_GRP, BUSYWAIT_KEY, BUSY_WAIT);
+ return readNumConfig(modemGroup(), BUSYWAIT_KEY, BUSY_WAIT);
}
void PPPData::setbusyWait(int n) {
- writeConfig(MODEM_GRP, BUSYWAIT_KEY, n);
+ writeConfig(modemGroup(), BUSYWAIT_KEY, n);
}
//
//Advanced "Modem" dialog
//
// defaults: InitString=ATZ, InitString1="" etc.
const QString PPPData::modemInitStr(int i) {
assert(i >= 0 && i < NumInitStrings);
if(i == 0)
- return readConfig(MODEM_GRP, INITSTR_KEY, "ATZ");
+ return readConfig(modemGroup(), INITSTR_KEY, "ATZ");
else
- return readConfig(MODEM_GRP, INITSTR_KEY + QString::number(i), "");
+ return readConfig(modemGroup(), INITSTR_KEY + QString::number(i), "");
}
void PPPData::setModemInitStr(int i, const QString &n) {
assert(i >= 0 && i < NumInitStrings);
QString k = INITSTR_KEY + (i > 0 ? QString::number(i) : "");
- writeConfig(MODEM_GRP, k, n);
+ writeConfig(modemGroup(), k, n);
}
const QString PPPData::modemInitResp() {
- return readConfig(MODEM_GRP, INITRESP_KEY, "OK");
+ return readConfig(modemGroup(), INITRESP_KEY, "OK");
}
void PPPData::setModemInitResp(const QString &n) {
- writeConfig(MODEM_GRP, INITRESP_KEY, n);
+ writeConfig(modemGroup(), INITRESP_KEY, n);
}
int PPPData::modemPreInitDelay() {
- return readNumConfig(MODEM_GRP, PREINITDELAY_KEY, 50);
+ return readNumConfig(modemGroup(), PREINITDELAY_KEY, 50);
}
void PPPData::setModemPreInitDelay(int n) {
- writeConfig(MODEM_GRP, PREINITDELAY_KEY, n);
+ writeConfig(modemGroup(), PREINITDELAY_KEY, n);
}
int PPPData::modemInitDelay() {
- return readNumConfig(MODEM_GRP, INITDELAY_KEY, 50);
+ return readNumConfig(modemGroup(), INITDELAY_KEY, 50);
}
void PPPData::setModemInitDelay(int n) {
- writeConfig(MODEM_GRP, INITDELAY_KEY, n);
+ writeConfig(modemGroup(), INITDELAY_KEY, n);
}
QString PPPData::modemNoDialToneDetectionStr() {
- return readConfig(MODEM_GRP, NODTDETECT_KEY, "ATX3");
+ return readConfig(modemGroup(), NODTDETECT_KEY, "ATX3");
}
void PPPData::setModemNoDialToneDetectionStr(const QString &n) {
- writeConfig(MODEM_GRP, NODTDETECT_KEY, n);
+ writeConfig(modemGroup(), NODTDETECT_KEY, n);
}
const QString PPPData::modemDialStr() {
- return readConfig(MODEM_GRP, DIALSTR_KEY, "ATDT");
+ return readConfig(modemGroup(), DIALSTR_KEY, "ATDT");
}
void PPPData::setModemDialStr(const QString &n) {
- writeConfig(MODEM_GRP, DIALSTR_KEY, n);
+ writeConfig(modemGroup(), DIALSTR_KEY, n);
}
const QString PPPData::modemConnectResp() {
- return readConfig(MODEM_GRP, CONNECTRESP_KEY, "CONNECT");
+ return readConfig(modemGroup(), CONNECTRESP_KEY, "CONNECT");
}
void PPPData::setModemConnectResp(const QString &n) {
- writeConfig(MODEM_GRP, CONNECTRESP_KEY, n);
+ writeConfig(modemGroup(), CONNECTRESP_KEY, n);
}
const QString PPPData::modemBusyResp() {
- return readConfig(MODEM_GRP, BUSYRESP_KEY, "BUSY");
+ return readConfig(modemGroup(), BUSYRESP_KEY, "BUSY");
}
void PPPData::setModemBusyResp(const QString &n) {
- writeConfig(MODEM_GRP, BUSYRESP_KEY, n);
+ writeConfig(modemGroup(), BUSYRESP_KEY, n);
}
const QString PPPData::modemNoCarrierResp() {
- return readConfig(MODEM_GRP, NOCARRIERRESP_KEY, "NO CARRIER");
+ return readConfig(modemGroup(), NOCARRIERRESP_KEY, "NO CARRIER");
}
void PPPData::setModemNoCarrierResp(const QString &n) {
- writeConfig(MODEM_GRP, NOCARRIERRESP_KEY, n);
+ writeConfig(modemGroup(), NOCARRIERRESP_KEY, n);
}
const QString PPPData::modemNoDialtoneResp() {
- return readConfig(MODEM_GRP, NODIALTONERESP_KEY, "NO DIALTONE");
+ return readConfig(modemGroup(), NODIALTONERESP_KEY, "NO DIALTONE");
}
void PPPData::setModemNoDialtoneResp(const QString &n) {
- writeConfig(MODEM_GRP, NODIALTONERESP_KEY, n);
+ writeConfig(modemGroup(), NODIALTONERESP_KEY, n);
}
const QString PPPData::modemHangupStr() {
- return readConfig(MODEM_GRP, HANGUPSTR_KEY, "+++ATH");
+ return readConfig(modemGroup(), HANGUPSTR_KEY, "+++ATH");
}
void PPPData::setModemHangupStr(const QString &n) {
- writeConfig(MODEM_GRP, HANGUPSTR_KEY, n);
+ writeConfig(modemGroup(), HANGUPSTR_KEY, n);
}
const QString PPPData::modemHangupResp() {
- return readConfig(MODEM_GRP, HANGUPRESP_KEY, "OK");
+ return readConfig(modemGroup(), HANGUPRESP_KEY, "OK");
}
void PPPData::setModemHangupResp(const QString &n) {
- writeConfig(MODEM_GRP, HANGUPRESP_KEY, n);
+ writeConfig(modemGroup(), HANGUPRESP_KEY, n);
}
const QString PPPData::modemAnswerStr() {
- return readConfig(MODEM_GRP, ANSWERSTR_KEY, "ATA");
+ return readConfig(modemGroup(), ANSWERSTR_KEY, "ATA");
}
QString PPPData::volumeOff() {
- return readConfig(MODEM_GRP, VOLUME_OFF, "M0L0");
+ return readConfig(modemGroup(), VOLUME_OFF, "M0L0");
}
void PPPData::setVolumeOff(const QString &s) {
- writeConfig(MODEM_GRP, VOLUME_OFF, s);
+ writeConfig(modemGroup(), VOLUME_OFF, s);
}
QString PPPData::volumeMedium() {
- return readConfig(MODEM_GRP, VOLUME_MEDIUM, "M1L1");
+ return readConfig(modemGroup(), VOLUME_MEDIUM, "M1L1");
}
void PPPData::setVolumeMedium(const QString &s) {
- writeConfig(MODEM_GRP, VOLUME_MEDIUM, s);
+ writeConfig(modemGroup(), VOLUME_MEDIUM, s);
}
QString PPPData::volumeHigh() {
- QString tmp = readConfig(MODEM_GRP, VOLUME_HIGH, "M1L3");
+ QString tmp = readConfig(modemGroup(), VOLUME_HIGH, "M1L3");
if(tmp == "M1L4")
tmp = "M1L3";
return tmp;
}
void PPPData::setVolumeHigh(const QString &s) {
- writeConfig(MODEM_GRP, VOLUME_HIGH, s);
+ writeConfig(modemGroup(), VOLUME_HIGH, s);
}
QString PPPData::volumeInitString() {
QString s;
switch(volume()) {
case 0:
s = volumeOff();
break;
case 1:
s = volumeMedium();
@@ -615,72 +615,72 @@ QString PPPData::volumeInitString() {
case 2:
s = volumeHigh();
break;
default:
s = volumeMedium();
}
return s;
}
int PPPData::volume() {
- return readNumConfig(MODEM_GRP, VOLUME_KEY, 1);
+ return readNumConfig(modemGroup(), VOLUME_KEY, 1);
}
void PPPData::setVolume(int i) {
- writeConfig(MODEM_GRP, VOLUME_KEY, i);
+ writeConfig(modemGroup(), VOLUME_KEY, i);
}
int PPPData::waitForDialTone() {
- return readNumConfig(MODEM_GRP, DIALTONEWAIT_KEY, 1);
+ return readNumConfig(modemGroup(), DIALTONEWAIT_KEY, 1);
}
void PPPData::setWaitForDialTone(int i) {
- writeConfig(MODEM_GRP, DIALTONEWAIT_KEY, i);
+ writeConfig(modemGroup(), DIALTONEWAIT_KEY, i);
}
void PPPData::setModemAnswerStr(const QString &n) {
- writeConfig(MODEM_GRP, ANSWERSTR_KEY, n);
+ writeConfig(modemGroup(), ANSWERSTR_KEY, n);
}
const QString PPPData::modemRingResp() {
- return readConfig(MODEM_GRP, RINGRESP_KEY, "RING");
+ return readConfig(modemGroup(), RINGRESP_KEY, "RING");
}
void PPPData::setModemRingResp(const QString &n) {
- writeConfig(MODEM_GRP, RINGRESP_KEY, n);
+ writeConfig(modemGroup(), RINGRESP_KEY, n);
}
const QString PPPData::modemAnswerResp() {
- return readConfig(MODEM_GRP, ANSWERRESP_KEY, "CONNECT");
+ return readConfig(modemGroup(), ANSWERRESP_KEY, "CONNECT");
}
void PPPData::setModemAnswerResp(const QString &n) {
- writeConfig(MODEM_GRP, ANSWERRESP_KEY, n);
+ writeConfig(modemGroup(), ANSWERRESP_KEY, n);
}
const QString PPPData::enter() {
- return readConfig(MODEM_GRP, ENTER_KEY, "CR");
+ return readConfig(modemGroup(), ENTER_KEY, "CR");
}
void PPPData::setEnter(const QString &n) {
- writeConfig(MODEM_GRP, ENTER_KEY, n);
+ writeConfig(modemGroup(), ENTER_KEY, n);
}
//
// functions to set/return account information
//
//returns number of accounts
int PPPData::count() const {
return highcount + 1;
}
@@ -1200,24 +1200,28 @@ bool PPPData::pppdRunning() const {
void PPPData::setpppdRunning(bool set) {
pppdisrunning = set;
}
int PPPData::pppdError() const {
return pppderror;
}
void PPPData::setpppdError(int err) {
pppderror = err;
}
+QString PPPData::modemGroup()
+{
+ return MODEM_GRP;
+}
// //
// // window position
// //
// void PPPData::winPosConWin(int& p_x, int& p_y) {
// p_x = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_X, QApplication::desktop()->width()/2-160);
// p_y = readNumConfig(WINPOS_GRP, WINPOS_CONWIN_Y, QApplication::desktop()->height()/2-55);
// }
// void PPPData::setWinPosConWin(int p_x, int p_y) {
// writeConfig(WINPOS_GRP, WINPOS_CONWIN_X, p_x);
// writeConfig(WINPOS_GRP, WINPOS_CONWIN_Y, p_y);
diff --git a/noncore/settings/networksettings/ppp/pppdata.h b/noncore/settings/networksettings/ppp/pppdata.h
index 57ce2fd..c4d7bc3 100644
--- a/noncore/settings/networksettings/ppp/pppdata.h
+++ b/noncore/settings/networksettings/ppp/pppdata.h
@@ -150,48 +150,49 @@ class Config;
// pppd errors
#define E_IF_TIMEOUT 1
#define E_PPPD_DIED 2
// window position
#define WINPOS_CONWIN_X "WindowPositionConWinX"
#define WINPOS_CONWIN_Y "WindowPositionConWinY"
#define WINPOS_STATWIN_X "WindowPositionStatWinX"
#define WINPOS_STATWIN_Y "WindowPositionStatWinY"
class PPPData {
public:
- PPPData();
- ~PPPData() {};
+ PPPData();
+ ~PPPData() {};
static PPPData* data();
- enum { NumInitStrings = 2 };
+ enum { NumInitStrings = 2 };
- // general functions
- bool open();
- void save();
- void cancel();
-// int access() const; // read/write access
+ // general functions
+ bool open();
+ void save();
+ void cancel();
- // function to read/write date to configuration file
- QString readConfig(const QString &, const QString &, const QString &);
- int readNumConfig(const QString &, const QString &, int);
- bool readListConfig(const QString &, const QString &,
+
+ // function to read/write date to configuration file
+ QString readConfig(const QString &, const QString &, const QString &);
+ int readNumConfig(const QString &, const QString &, int);
+ bool readListConfig(const QString &, const QString &,
QStringList &, char sep = ',');
- void writeConfig(const QString &, const QString &, const QString &);
- void writeConfig(const QString &, const QString &, int);
- void writeListConfig(const QString &, const QString &,
+ void writeConfig(const QString &, const QString &, const QString &);
+ void writeConfig(const QString &, const QString &, int);
+ void writeListConfig(const QString &, const QString &,
QStringList &, char sep = ',');
- // return the current account group
- QString currentGroup() { return cgroup; }
+ // return the current account group
+ QString currentGroup() { return cgroup; }
+ QString modemGroup();
// functions to set/get general kppp info
QString password() const;
void setPassword(const QString &);
const QString defaultAccount();
void setDefaultAccount(const QString &);
void set_xserver_exit_disconnect(bool set);
bool get_xserver_exit_disconnect();
void setPPPDebug(bool set);
diff --git a/noncore/settings/networksettings/ppp/pppmodule.cpp b/noncore/settings/networksettings/ppp/pppmodule.cpp
index da17e26..e13f8c8 100644
--- a/noncore/settings/networksettings/ppp/pppmodule.cpp
+++ b/noncore/settings/networksettings/ppp/pppmodule.cpp
@@ -1,23 +1,28 @@
#include "pppconfig.h"
#include "pppmodule.h"
#include "pppdata.h"
#include "kpppwidget.h"
#include "interfaceinformationimp.h"
//#include "devices.h"
/**
* Constructor, find all of the possible interfaces
*/
-PPPModule::PPPModule() : Module() {
+PPPModule::PPPModule() : Module()
+{
+ Interface *iface;
+ iface = new Interface( 0, "device" );
+ iface->setHardwareName( "account" );
+ list.append( iface );
}
/**
* Delete any interfaces that we own.
*/
PPPModule::~PPPModule(){
Interface *i;
for ( i=list.first(); i != 0; i=list.next() )
delete i;
}
/**
@@ -33,40 +38,35 @@ void PPPModule::setProfile(const QString &newProfile){
* @return QString the icon name (minus .png, .gif etc)
*/
QString PPPModule::getPixmapName(Interface* ){
return "ppp";
}
/**
* Check to see if the interface i is owned by this module.
* @param Interface* interface to check against
* @return bool true if i is owned by this module, false otherwise.
*/
bool PPPModule::isOwner(Interface *i){
- if(!i->getInterfaceName().upper().contains("PPP"))
- return false;
-
- i->setHardwareName("PPP");
- list.append(i);
- return true;
+ return list.find( i ) != -1;
}
/**
* Create, and return the WLANConfigure Module
* @return QWidget* pointer to this modules configure.
*/
QWidget *PPPModule::configure(Interface *i){
qDebug("return ModemWidget");
- PPPConfigWidget *pppconfig = new PPPConfigWidget( 0, "PPPConfig", false, Qt::WDestructiveClose );
-// pppconfig->setProfile(profile);
+ PPPConfigWidget *pppconfig = new PPPConfigWidget( 0, "PPPConfig", false,
+ Qt::WDestructiveClose );
return pppconfig;
}
/**
* Create, and return the Information Module
* @return QWidget* pointer to this modules info.
*/
QWidget *PPPModule::information(Interface *i){
// We don't have any advanced pppd information widget yet :-D
// TODO ^
qDebug("return PPPModule::information");
InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i);
@@ -88,34 +88,38 @@ QList<Interface> PPPModule::getInterfaces(){
* @param name the name of the type of interface that should be created given
* by possibleNewInterfaces();
* @return Interface* NULL if it was unable to be created.
*/
Interface *PPPModule::addNewInterface(const QString &newInterface){
qDebug("try to add iface %s",newInterface.latin1());
PPPConfigWidget imp(0, "PPPConfigImp", true);
imp.showMaximized();
if(imp.exec() == QDialog::Accepted ){
qDebug("ACCEPTED");
- return new Interface( 0, newInterface );
PPPData::data()->save();
+ Interface *iface;
+ iface = new Interface( 0, PPPData::data()->modemDevice() );
+ iface->setHardwareName( PPPData::data()->accname() );
+ list.append( iface );
+ return iface;
}
return NULL;
}
/**
* Attempts to remove the interface, doesn't delete i
* @return bool true if successfull, false otherwise.
*/
bool PPPModule::remove(Interface*){
// Can't remove a hardware device, you can stop it though.
return false;
}
void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces)
{
- qDebug("here");
- newIfaces.insert(QObject::tr("PPP") ,QObject::tr("generic ppp device"));
+ newIfaces.insert(QObject::tr("PPP") ,
+ QObject::tr("generic ppp device"));
}