summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/modem.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings/ppp/modem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
index 3dbc8c3..f3f2639 100644
--- a/noncore/settings/networksettings/ppp/modem.cpp
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -46,25 +46,25 @@
#ifndef _PATH_RESCONF
#define _PATH_RESCONF "/etc/resolv.conf"
#endif
#define strlcpy strcpy
#include "auth.h"
#include "modem.h"
#include "pppdata.h"
#define qError qDebug
#define MY_ASSERT(x) if (!(x)) { \
- qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \
+ ofatal << "ASSERT: \"" << #x << "\" in " << __FILE__ << " (" << __LINE__ << ")\n" << oendl; \
exit(1); }
static sigjmp_buf jmp_buffer;
//Modem *Modem::modem = 0;
const char* pppdPath() {
// wasting a few bytes
static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)];
static char *pppdPath = 0L;
@@ -156,25 +156,25 @@ speed_t Modem::modemspeed() {
return B38400;
break;
}
}
bool Modem::opentty() {
// int flags;
//begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
close(modemfd);
device = _pppdata->modemDevice();
if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) {
- qDebug("error opening modem device !");
+ odebug << "error opening modem device !" << oendl;
errmsg = QObject::tr("Unable to open modem.");
return false;
}
//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
//}
#if 0
if(_pppdata->UseCDLine()) {
if(ioctl(modemfd, TIOCMGET, &flags) == -1) {
errmsg = QObject::tr("Unable to detect state of CD line.");
::close(modemfd);
modemfd = -1;
@@ -297,56 +297,56 @@ void Modem::notify(const QObject *receiver, const char *member) {
void Modem::stop() {
disconnect(SIGNAL(charWaiting(unsigned char)));
stopNotifier();
}
void Modem::startNotifier() {
if(modemfd >= 0) {
if(sn == 0) {
sn = new QSocketNotifier(modemfd, QSocketNotifier::Read, this);
connect(sn, SIGNAL(activated(int)), SLOT(readtty(int)));
- qDebug("QSocketNotifier started!");
+ odebug << "QSocketNotifier started!" << oendl;
} else {
- qDebug("QSocketNotifier re-enabled!");
+ odebug << "QSocketNotifier re-enabled!" << oendl;
sn->setEnabled(true);
}
}
}
void Modem::stopNotifier() {
if(sn != 0) {
sn->setEnabled(false);
disconnect(sn);
delete sn;
sn = 0;
- qDebug( "QSocketNotifier stopped!" );
+ odebug << "QSocketNotifier stopped!" << oendl;
}
}
void Modem::flush() {
char c;
while(read(modemfd, &c, 1) == 1);
}
bool Modem::writeChar(unsigned char c) {
int s;
do {
s = write(modemfd, &c, 1);
if (s < 0) {
- qError( "write() in Modem::writeChar failed" );
+ oerr << "write() in Modem::writeChar failed" << oendl;
return false;
}
} while(s == 0);
return true;
}
bool Modem::writeLine(const char *buf) {
int len = strlen(buf);
char *b = new char[len+2];
memcpy(b, buf, len);
@@ -356,25 +356,25 @@ bool Modem::writeLine(const char *buf) {
b[len++]='\n';
else if(term == "CR")
b[len++]='\r';
else if(term == "CR/LF") {
b[len++]='\r';
b[len++]='\n';
}
int l = len;
while(l) {
int wr = write(modemfd, &b[len-l], l);
if(wr < 0) {
// TODO do something meaningful with the error code (or ignore it
- qError( "write() in Modem::writeLine failed" );
+ oerr << "write() in Modem::writeLine failed" << oendl;
delete[] b;
return false;
}
l -= wr;
}
delete[] b;
return true;
}
bool Modem::hangup() {
// this should really get the modem to hang up and go into command mode
@@ -465,25 +465,25 @@ void Modem::escape_to_command_mode() {
const QString Modem::modemMessage() {
return errmsg;
}
QString Modem::parseModemSpeed(const QString &s) {
// this is a small (and bad) parser for modem speeds
int rx = -1;
int tx = -1;
int i;
QString result;
- qDebug( "Modem reported result string: %s", s.latin1());
+ odebug << "Modem reported result string: " << s.latin1() << "" << oendl;
const int RXMAX = 7;
const int TXMAX = 2;
QRegExp rrx[RXMAX] = {
QRegExp("[0-9]+[:/ ]RX", false),
QRegExp("[0-9]+RX", false),
QRegExp("[/: -][0-9]+[/: ]", false),
QRegExp("[/: -][0-9]+$", false),
QRegExp("CARRIER [^0-9]*[0-9]+", false),
QRegExp("CONNECT [^0-9]*[0-9]+", false),
QRegExp("[0-9]+") // panic mode
};
@@ -551,131 +551,131 @@ QString Modem::parseModemSpeed(const QString &s) {
}
}
if(rx == -1 && tx == -1)
result = QObject::tr("Unknown speed");
else if(tx == -1)
result.setNum(rx);
else if(rx == -1) // should not happen
result.setNum(tx);
else
result.sprintf("%d/%d", rx, tx);
- qDebug( "The parsed result is: %s", result.latin1());
+ odebug << "The parsed result is: " << result.latin1() << "" << oendl;
return result;
}
// Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if
// a lock file can't be created ( permission problem )
int Modem::lockdevice() {
int fd;
char newlock[80]=""; // safe
if(!_pppdata->modemLockFile()) {
- qDebug("The user doesn't want a lockfile.");
+ odebug << "The user doesn't want a lockfile." << oendl;
return 0;
}
if (modem_is_locked)
return 1;
QString lockfile = LOCK_DIR"/LCK..";
lockfile += _pppdata->modemDevice().mid(5); // append everything after /dev/
if(access(QFile::encodeName(lockfile), F_OK) == 0) {
// if ((fd = Requester::rq->
if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) {
// Mario: it's not necessary to read more than lets say 32 bytes. If
// file has more than 32 bytes, skip the rest
char oldlock[33]; // safe
int sz = read(fd, &oldlock, 32);
close (fd);
if (sz <= 0)
return 1;
oldlock[sz] = '\0';
- qDebug( "Device is locked by: %s", oldlock);
+ odebug << "Device is locked by: " << oldlock << "" << oendl;
int oldpid;
int match = sscanf(oldlock, "%d", &oldpid);
// found a pid in lockfile ?
if (match < 1 || oldpid <= 0)
return 1;
// check if process exists
if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH)
return 1;
- qDebug( "lockfile is stale" );
+ odebug << "lockfile is stale" << oendl;
}
}
fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT);
if(fd >= 0) {
sprintf(newlock,"%010d\n", getpid());
- qDebug("Locking Device: %s", newlock);
+ odebug << "Locking Device: " << newlock << "" << oendl;
write(fd, newlock, strlen(newlock));
close(fd);
modem_is_locked=true;
return 0;
}
return -1;
}
// UnLock modem device
void Modem::unlockdevice() {
if (modem_is_locked) {
- qDebug( "UnLocking Modem Device" );
+ odebug << "UnLocking Modem Device" << oendl;
close(modemfd);
modemfd = -1;
unlink(lockfile);
lockfile[0] = '\0';
modem_is_locked=false;
}
}
int Modem::openLockfile( QString lockfile, int flags)
{
int fd;
int mode;
flags = O_RDONLY;
if(flags == O_WRONLY|O_TRUNC|O_CREAT)
mode = 0644;
else
mode = 0;
lockfile = LOCK_DIR;
lockfile += "/LCK..";
lockfile += device.right( device.length() - device.findRev("/") -1 );
- qDebug("lockfile >%s<",lockfile.latin1());
+ odebug << "lockfile >" << lockfile.latin1() << "<" << oendl;
// TODO:
// struct stat st;
// if(stat(lockfile.data(), &st) == -1) {
// if(errno == EBADF)
// return -1;
// } else {
// // make sure that this is a regular file
// if(!S_ISREG(st.st_mode))
// return -1;
// }
if ((fd = open(lockfile, flags, mode)) == -1) {
- qDebug("error opening lockfile!");
+ odebug << "error opening lockfile!" << oendl;
lockfile = QString::null;
fd = open(DEVNULL, O_RDONLY);
} else
fchown(fd, 0, 0);
return fd;
}
void alarm_handler(int) {
// fprintf(stderr, "alarm_handler(): Received SIGALRM\n");
@@ -918,60 +918,60 @@ bool Modem::execpppd(const char *arguments) {
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);
+ odebug << "In parent: pppd pid " << pppdPid << "\n" << oendl;
close(modemfd);
::close( m_pppdLOG[1] );
// set it to nonblocking io
int flag = ::fcntl( m_pppdLOG[0], F_GETFL );
if ( !(flag & O_NONBLOCK) ) {
- qDebug("Setting nonblocking io");
+ odebug << "Setting nonblocking io" << oendl;
flag |= O_NONBLOCK;
::fcntl(m_pppdLOG[0], F_SETFL, flag );
}
delete m_modemDebug;
m_modemDebug = new QSocketNotifier(m_pppdLOG[0], QSocketNotifier::Read, this );
connect(m_modemDebug, SIGNAL(activated(int) ),
this, SLOT(slotModemDebug(int) ) );
modemfd = -1;
m_pppdDev = QString::fromLatin1("ppp0");
return true;
break;
}
}
bool Modem::killpppd() {
- qDebug("In killpppd and pid is %d", pppdPid );
+ odebug << "In killpppd and pid is " << pppdPid << "" << oendl;
if(pppdPid > 0) {
delete m_modemDebug;
m_modemDebug = 0;
- qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid);
+ odebug << "In killpppd(): Sending SIGTERM to " << pppdPid << "\n" << oendl;
if(kill(pppdPid, SIGTERM) < 0) {
- qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid);
+ odebug << "Error terminating " << pppdPid << ". Sending SIGKILL\n" << oendl;
if(kill(pppdPid, SIGKILL) < 0) {
- qDebug("Error killing %d\n", pppdPid);
+ odebug << "Error killing " << pppdPid << "\n" << oendl;
return false;
}
}
}
return true;
}
void Modem::parseargs(char* buf, char** args) {
int nargs = 0;
int quotes;
@@ -1026,46 +1026,46 @@ void Modem::killPPPDaemon()
killpppd();
}
int Modem::pppdExitStatus()
{
return _pppdExitStatus;
}
int Modem::openResolv(int flags)
{
int fd;
if ((fd = open(_PATH_RESCONF, flags)) == -1) {
- qDebug("error opening resolv.conf!");
+ odebug << "error opening resolv.conf!" << oendl;
fd = open(DEVNULL, O_RDONLY);
}
return fd;
}
bool Modem::setHostname(const QString & name)
{
return sethostname(name, name.length()) == 0;
}
QString Modem::pppDevice()const {
return m_pppdDev;
}
void Modem::setPPPDevice( const QString& dev ) {
m_pppdDev = dev;
}
pid_t Modem::pppPID()const {
return pppdPid;
}
void Modem::setPPPDPid( pid_t pid ) {
- qDebug("Modem setting pid");
+ odebug << "Modem setting pid" << oendl;
_pppdExitStatus = -1;
pppdPid = pid;
modemfd = -1;
}
void Modem::slotModemDebug(int fd) {
char buf[2049];
int len;
// read in pppd data look for Using interface
// then read the interface
// we limit to 10 device now 0-9
if((len = ::read(fd, buf, 2048)) > 0) {