summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2020-10-08 16:09:53 +0200
committerSimon Rettberg2020-10-08 16:09:53 +0200
commit71d5c8373dc76fb1b994a1185ecae3ae8d42b689 (patch)
tree91ad0bb89bcdfa9fa596bbbaad434630d9384e44 /src
parentFix sign error (diff)
downloadbwlp-screensaver-71d5c8373dc76fb1b994a1185ecae3ae8d42b689.tar.gz
bwlp-screensaver-71d5c8373dc76fb1b994a1185ecae3ae8d42b689.tar.xz
bwlp-screensaver-71d5c8373dc76fb1b994a1185ecae3ae8d42b689.zip
Add sanity checks to RPC parse, so we don't reset everythingv29r2v29r1
If we get a malformed empty reply, we would previously reset all the variables, so the display text would reset to a generic string.
Diffstat (limited to 'src')
-rw-r--r--src/saverwidget.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/saverwidget.cpp b/src/saverwidget.cpp
index 359c2bd..1a4a14c 100644
--- a/src/saverwidget.cpp
+++ b/src/saverwidget.cpp
@@ -113,12 +113,17 @@ void SaverWidget::reloadValues()
connect(_unixSocket, &QLocalSocket::connected, [=]() {
qDebug() << "Connected to daewmweon";
_unixSocket->write((QLatin1String("get ") + _display).toLocal8Bit());
- QTimer::singleShot(1000, [this]() {
+ QTimer::singleShot(2000, [this]() {
_unixSocket->disconnectFromServer();
+ this->parseDaemonData();
});
});
connect(_unixSocket, QOverload<QLocalSocket::LocalSocketError>::of(&QLocalSocket::error), [=](QLocalSocket::LocalSocketError err) {
- qDebug() << "Local socket error:" << err;
+ if (err != QLocalSocket::PeerClosedError) {
+ qDebug() << "Local socket error:" << err;
+ } else {
+ this->parseDaemonData();
+ }
});
connect(_unixSocket, &QLocalSocket::disconnected, this, &SaverWidget::parseDaemonData);
_unixSocket->connectToServer("/run/idle-daemon");
@@ -131,8 +136,9 @@ void SaverWidget::parseDaemonData()
#define SEC_NONE 0
#define SEC_GENERAL 1
#define SEC_ME 2
-#define STORE(x) else if (key == QLatin1String( #x )) x = value.toString()
+#define STORE(x) else if (key == QLatin1String( #x )) ok++, x = value.toString()
int sec = SEC_NONE;
+ int ok = 0;
QString nextAction, nextActionTime, logoutTime, locked;
while (!ts.atEnd()) {
line = ts.readLine();
@@ -142,8 +148,10 @@ void SaverWidget::parseDaemonData()
// Section
if (line == QLatin1String("[General]")) {
sec = SEC_GENERAL;
+ ok++;
} else if ( line == "[" + _display + "]") {
sec = SEC_ME;
+ ok++;
} else {
sec = SEC_NONE;
}
@@ -165,6 +173,8 @@ void SaverWidget::parseDaemonData()
}
}
}
+ if (ok < 3)
+ return; // Bad data received, ignore
if (nextAction.isEmpty() || nextAction == QLatin1String("none") || nextActionTime.isEmpty()) {
_shutdownDeadline = 0;
} else {