wpa_gui: Debug enhancement

Instead of calling a dummy printf function use preprocessor to determine
if debugging mode is enabled. Also use native Qt debug function.

Signed-off-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com>
This commit is contained in:
Arkadiusz (Arkq) Bokowy 2015-02-14 17:32:02 +01:00 committed by Jouni Malinen
parent 2b892d442a
commit 7fe7a3a51f

View file

@ -23,15 +23,14 @@
#include "userdatarequest.h" #include "userdatarequest.h"
#include "networkconfig.h" #include "networkconfig.h"
#if 1
/* Silence stdout */ #ifndef QT_NO_DEBUG
#define printf wpagui_printf #define debug(M, ...) qDebug("DEBUG %d: " M, __LINE__, ##__VA_ARGS__)
static int wpagui_printf(const char *, ...) #else
{ #define debug(M, ...) do {} while (0)
return 0;
}
#endif #endif
WpaGui::WpaGui(QApplication *_app, QWidget *parent, const char *, Qt::WFlags) WpaGui::WpaGui(QApplication *_app, QWidget *parent, const char *, Qt::WFlags)
: QMainWindow(parent), app(_app) : QMainWindow(parent), app(_app)
{ {
@ -163,8 +162,8 @@ WpaGui::WpaGui(QApplication *_app, QWidget *parent, const char *, Qt::WFlags)
timer->start(1000); timer->start(1000);
if (openCtrlConnection(ctrl_iface) < 0) { if (openCtrlConnection(ctrl_iface) < 0) {
printf("Failed to open control connection to " debug("Failed to open control connection to "
"wpa_supplicant.\n"); "wpa_supplicant.");
} }
updateStatus(); updateStatus();
@ -295,8 +294,8 @@ int WpaGui::openCtrlConnection(const char *ifname)
if (strcmp(dent->d_name, ".") == 0 || if (strcmp(dent->d_name, ".") == 0 ||
strcmp(dent->d_name, "..") == 0) strcmp(dent->d_name, "..") == 0)
continue; continue;
printf("Selected interface '%s'\n", debug("Selected interface '%s'",
dent->d_name); dent->d_name);
ctrl_iface = strdup(dent->d_name); ctrl_iface = strdup(dent->d_name);
break; break;
} }
@ -373,7 +372,7 @@ int WpaGui::openCtrlConnection(const char *ifname)
monitor_conn = NULL; monitor_conn = NULL;
} }
printf("Trying to connect to '%s'\n", cfile); debug("Trying to connect to '%s'", cfile);
ctrl_conn = wpa_ctrl_open(cfile); ctrl_conn = wpa_ctrl_open(cfile);
if (ctrl_conn == NULL) { if (ctrl_conn == NULL) {
free(cfile); free(cfile);
@ -386,7 +385,7 @@ int WpaGui::openCtrlConnection(const char *ifname)
return -1; return -1;
} }
if (wpa_ctrl_attach(monitor_conn)) { if (wpa_ctrl_attach(monitor_conn)) {
printf("Failed to attach to wpa_supplicant\n"); debug("Failed to attach to wpa_supplicant");
wpa_ctrl_close(monitor_conn); wpa_ctrl_close(monitor_conn);
monitor_conn = NULL; monitor_conn = NULL;
wpa_ctrl_close(ctrl_conn); wpa_ctrl_close(ctrl_conn);
@ -447,9 +446,9 @@ int WpaGui::ctrlRequest(const char *cmd, char *buf, size_t *buflen)
return -3; return -3;
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), buf, buflen, NULL); ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), buf, buflen, NULL);
if (ret == -2) if (ret == -2)
printf("'%s' command timed out.\n", cmd); debug("'%s' command timed out.", cmd);
else if (ret < 0) else if (ret < 0)
printf("'%s' command failed.\n", cmd); debug("'%s' command failed.", cmd);
return ret; return ret;
} }
@ -705,13 +704,13 @@ void WpaGui::updateNetworks()
void WpaGui::helpIndex() void WpaGui::helpIndex()
{ {
printf("helpIndex\n"); debug("helpIndex");
} }
void WpaGui::helpContents() void WpaGui::helpContents()
{ {
printf("helpContents\n"); debug("helpContents");
} }
@ -806,9 +805,9 @@ void WpaGui::ping()
len = sizeof(buf) - 1; len = sizeof(buf) - 1;
if (ctrlRequest("PING", buf, &len) < 0) { if (ctrlRequest("PING", buf, &len) < 0) {
printf("PING failed - trying to reconnect\n"); debug("PING failed - trying to reconnect");
if (openCtrlConnection(ctrl_iface) >= 0) { if (openCtrlConnection(ctrl_iface) >= 0) {
printf("Reconnected successfully\n"); debug("Reconnected successfully");
pingsToStatusUpdate = 0; pingsToStatusUpdate = 0;
} }
} }
@ -1002,8 +1001,8 @@ void WpaGui::enableNetwork(const QString &sel)
if (cmd.contains(QRegExp("^\\d+:"))) if (cmd.contains(QRegExp("^\\d+:")))
cmd.truncate(cmd.indexOf(':')); cmd.truncate(cmd.indexOf(':'));
else if (!cmd.startsWith("all")) { else if (!cmd.startsWith("all")) {
printf("Invalid editNetwork '%s'\n", debug("Invalid editNetwork '%s'",
cmd.toAscii().constData()); cmd.toAscii().constData());
return; return;
} }
cmd.prepend("ENABLE_NETWORK "); cmd.prepend("ENABLE_NETWORK ");
@ -1021,8 +1020,8 @@ void WpaGui::disableNetwork(const QString &sel)
if (cmd.contains(QRegExp("^\\d+:"))) if (cmd.contains(QRegExp("^\\d+:")))
cmd.truncate(cmd.indexOf(':')); cmd.truncate(cmd.indexOf(':'));
else if (!cmd.startsWith("all")) { else if (!cmd.startsWith("all")) {
printf("Invalid editNetwork '%s'\n", debug("Invalid editNetwork '%s'",
cmd.toAscii().constData()); cmd.toAscii().constData());
return; return;
} }
cmd.prepend("DISABLE_NETWORK "); cmd.prepend("DISABLE_NETWORK ");
@ -1111,8 +1110,8 @@ void WpaGui::removeNetwork(const QString &sel)
if (cmd.contains(QRegExp("^\\d+:"))) if (cmd.contains(QRegExp("^\\d+:")))
cmd.truncate(cmd.indexOf(':')); cmd.truncate(cmd.indexOf(':'));
else if (!cmd.startsWith("all")) { else if (!cmd.startsWith("all")) {
printf("Invalid editNetwork '%s'\n", debug("Invalid editNetwork '%s'",
cmd.toAscii().constData()); cmd.toAscii().constData());
return; return;
} }
cmd.prepend("REMOVE_NETWORK "); cmd.prepend("REMOVE_NETWORK ");
@ -1175,8 +1174,8 @@ int WpaGui::getNetworkDisabled(const QString &sel)
size_t reply_len = sizeof(reply) - 1; size_t reply_len = sizeof(reply) - 1;
int pos = cmd.indexOf(':'); int pos = cmd.indexOf(':');
if (pos < 0) { if (pos < 0) {
printf("Invalid getNetworkDisabled '%s'\n", debug("Invalid getNetworkDisabled '%s'",
cmd.toAscii().constData()); cmd.toAscii().constData());
return -1; return -1;
} }
cmd.truncate(pos); cmd.truncate(pos);
@ -1267,8 +1266,8 @@ void WpaGui::saveConfig()
void WpaGui::selectAdapter( const QString & sel ) void WpaGui::selectAdapter( const QString & sel )
{ {
if (openCtrlConnection(sel.toAscii().constData()) < 0) if (openCtrlConnection(sel.toAscii().constData()) < 0)
printf("Failed to open control connection to " debug("Failed to open control connection to "
"wpa_supplicant.\n"); "wpa_supplicant.");
updateStatus(); updateStatus();
updateNetworks(); updateNetworks();
} }
@ -1700,13 +1699,13 @@ bool WpaGui::serviceRunning()
scm = OpenSCManager(0, 0, SC_MANAGER_CONNECT); scm = OpenSCManager(0, 0, SC_MANAGER_CONNECT);
if (!scm) { if (!scm) {
printf("OpenSCManager failed: %d\n", (int) GetLastError()); debug("OpenSCManager failed: %d", (int) GetLastError());
return false; return false;
} }
svc = OpenService(scm, WPASVC_NAME, SERVICE_QUERY_STATUS); svc = OpenService(scm, WPASVC_NAME, SERVICE_QUERY_STATUS);
if (!svc) { if (!svc) {
printf("OpenService failed: %d\n\n", (int) GetLastError()); debug("OpenService failed: %d", (int) GetLastError());
CloseServiceHandle(scm); CloseServiceHandle(scm);
return false; return false;
} }