From cd1614fd75d9d66cf4b13114a4c171e221ec399b Mon Sep 17 00:00:00 2001 From: Akira Ohgaki <akiraohgaki@gmail.com> Date: Thu, 29 Sep 2016 15:46:20 +0900 Subject: [PATCH] Validation of metadata --- src/handlers/xdgurl.cpp | 32 ++++++++++++++++++++++++++++++++ src/handlers/xdgurl.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/handlers/xdgurl.cpp b/src/handlers/xdgurl.cpp index 136d6b2..143a16b 100644 --- a/src/handlers/xdgurl.cpp +++ b/src/handlers/xdgurl.cpp @@ -63,6 +63,7 @@ QJsonObject XdgUrl::_parse() QString XdgUrl::_convertPathString(const QString &path) { QString newPath = path; + if (newPath.contains("$HOME")) { newPath.replace("$HOME", Utility::File::homePath()); } @@ -72,6 +73,7 @@ QString XdgUrl::_convertPathString(const QString &path) else if (newPath.contains("$KDE_DATA")) { newPath.replace("$KDE_DATA", Utility::File::kdeDataHomePath()); } + return newPath; } @@ -134,10 +136,13 @@ bool XdgUrl::_installPlasmapkg(const QString &path, const QString &type) QProcess process; QStringList arguments; arguments << "-t" << type << "-i" << path; + process.start("plasmapkg2", arguments); + if (process.waitForFinished()) { return true; } + return false; } @@ -200,6 +205,33 @@ bool XdgUrl::_install() * Public slots */ +bool XdgUrl::isValid() +{ + bool isValid = true; + + if (_meta["scheme"].toString() != "xdg" && _meta["scheme"].toString() != "xdgs") { + isValid = false; + } + + if (_meta["command"].toString() != "download" && _meta["command"].toString() != "install") { + isValid = false; + } + + if (!QUrl(_meta["url"].toString()).isValid()) { + isValid = false; + } + + if (!_destinations.contains(_meta["type"].toString())) { + isValid = false; + } + + if (_meta["filename"].toString().isEmpty()) { + isValid = false; + } + + return isValid; +} + bool XdgUrl::process() { return true; diff --git a/src/handlers/xdgurl.h b/src/handlers/xdgurl.h index 03001b5..c705843 100644 --- a/src/handlers/xdgurl.h +++ b/src/handlers/xdgurl.h @@ -43,6 +43,7 @@ private: private slots: public slots: + bool isValid(); bool process(); signals: -- GitLab