Port server code from Qt4 to Qt5

Verification/testing of porting changes is pending
This commit is contained in:
Srivats P 2018-03-15 19:34:42 +05:30
parent 9f2be179d0
commit 9f4b70c5a8
4 changed files with 16 additions and 17 deletions

View File

@ -33,7 +33,7 @@ class PacketBuffer;
class QIODevice; class QIODevice;
// TODO: send notification back to client(s) // TODO: send notification back to client(s)
#define notify qWarning #define Xnotify qWarning
class AbstractPort class AbstractPort
{ {

View File

@ -350,14 +350,14 @@ void PcapPort::PortMonitor::stop()
*/ */
PcapPort::PortCapturer::PortCapturer(const char *device) PcapPort::PortCapturer::PortCapturer(const char *device)
{ {
device_ = QString::fromAscii(device); device_ = QString::fromLatin1(device);
stop_ = false; stop_ = false;
state_ = kNotStarted; state_ = kNotStarted;
if (!capFile_.open()) if (!capFile_.open())
qWarning("Unable to open temp cap file"); qWarning("Unable to open temp cap file");
qDebug("cap file = %s", capFile_.fileName().toAscii().constData()); qDebug("cap file = %s", qPrintable(capFile_.fileName()));
dumpHandle_ = NULL; dumpHandle_ = NULL;
handle_ = NULL; handle_ = NULL;
@ -381,7 +381,7 @@ void PcapPort::PortCapturer::run()
goto _exit; goto _exit;
} }
_retry: _retry:
handle_ = pcap_open_live(device_.toAscii().constData(), 65535, handle_ = pcap_open_live(qPrintable(device_), 65535,
flag, 1000 /* ms */, errbuf); flag, 1000 /* ms */, errbuf);
if (handle_ == NULL) if (handle_ == NULL)
@ -389,20 +389,19 @@ _retry:
if (flag && QString(errbuf).contains("promiscuous")) if (flag && QString(errbuf).contains("promiscuous"))
{ {
qDebug("%s:can't set promiscuous mode, trying non-promisc", qDebug("%s:can't set promiscuous mode, trying non-promisc",
device_.toAscii().constData()); qPrintable(device_));
flag = 0; flag = 0;
goto _retry; goto _retry;
} }
else else
{ {
qDebug("%s: Error opening port %s: %s\n", __FUNCTION__, qDebug("%s: Error opening port %s: %s\n", __FUNCTION__,
device_.toAscii().constData(), errbuf); qPrintable(device_), errbuf);
goto _exit; goto _exit;
} }
} }
dumpHandle_ = pcap_dump_open(handle_, dumpHandle_ = pcap_dump_open(handle_, qPrintable(capFile_.fileName()));
capFile_.fileName().toAscii().constData());
state_ = kRunning; state_ = kRunning;
while (1) while (1)
{ {
@ -492,7 +491,7 @@ QFile* PcapPort::PortCapturer::captureFile()
PcapPort::EmulationTransceiver::EmulationTransceiver(const char *device, PcapPort::EmulationTransceiver::EmulationTransceiver(const char *device,
DeviceManager *deviceManager) DeviceManager *deviceManager)
{ {
device_ = QString::fromAscii(device); device_ = QString::fromLatin1(device);
deviceManager_ = deviceManager; deviceManager_ = deviceManager;
stop_ = false; stop_ = false;
state_ = kNotStarted; state_ = kNotStarted;
@ -565,7 +564,7 @@ _retry:
{ {
if (flags && QString(errbuf).contains("promiscuous")) if (flags && QString(errbuf).contains("promiscuous"))
{ {
notify("Unable to set promiscuous mode on <%s> - " Xnotify("Unable to set promiscuous mode on <%s> - "
"device emulation will not work", qPrintable(device_)); "device emulation will not work", qPrintable(device_));
goto _exit; goto _exit;
} }
@ -580,7 +579,7 @@ _retry:
#endif #endif
else else
{ {
notify("Unable to open <%s> [%s] - device emulation will not work", Xnotify("Unable to open <%s> [%s] - device emulation will not work",
qPrintable(device_), errbuf); qPrintable(device_), errbuf);
goto _exit; goto _exit;
} }

View File

@ -22,12 +22,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "pcapextra.h" #include "pcapextra.h"
#include "../common/sign.h" #include "../common/sign.h"
#define notify qWarning // FIXME #define Xnotify qWarning // FIXME
PcapRxStats::PcapRxStats(const char *device, StreamStats &portStreamStats) PcapRxStats::PcapRxStats(const char *device, StreamStats &portStreamStats)
: streamStats_(portStreamStats) : streamStats_(portStreamStats)
{ {
device_ = QString::fromAscii(device); device_ = QString::fromLatin1(device);
stop_ = false; stop_ = false;
state_ = kNotStarted; state_ = kNotStarted;
isDirectional_ = true; isDirectional_ = true;
@ -65,12 +65,12 @@ void PcapRxStats::run()
flags, 100 /* ms */, errbuf); flags, 100 /* ms */, errbuf);
if (handle_ == NULL) { if (handle_ == NULL) {
if (flags && QString(errbuf).contains("promiscuous")) { if (flags && QString(errbuf).contains("promiscuous")) {
notify("Unable to set promiscuous mode on <%s> - " Xnotify("Unable to set promiscuous mode on <%s> - "
"stream stats rx will not work", qPrintable(device_)); "stream stats rx will not work", qPrintable(device_));
goto _exit; goto _exit;
} }
else { else {
notify("Unable to open <%s> [%s] - stream stats rx will not work", Xnotify("Unable to open <%s> [%s] - stream stats rx will not work",
qPrintable(device_), errbuf); qPrintable(device_), errbuf);
goto _exit; goto _exit;
} }

View File

@ -88,7 +88,7 @@ bool WinPcapPort::hasExclusiveControl()
+ "/bindconfig.exe"); + "/bindconfig.exe");
int exitCode; int exitCode;
qDebug("%s: %s", __FUNCTION__, portName.toAscii().constData()); qDebug("%s: %s", __FUNCTION__, qPrintable(portName));
if (!QFile::exists(bindConfigFilePath)) if (!QFile::exists(bindConfigFilePath))
return false; return false;
@ -111,7 +111,7 @@ bool WinPcapPort::setExclusiveControl(bool exclusive)
+ "/bindconfig.exe"); + "/bindconfig.exe");
QString status; QString status;
qDebug("%s: %s", __FUNCTION__, portName.toAscii().constData()); qDebug("%s: %s", __FUNCTION__, qPrintable(portName));
if (!QFile::exists(bindConfigFilePath)) if (!QFile::exists(bindConfigFilePath))
return false; return false;