File indexing completed on 2025-01-05 05:07:03

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2022 Lucas Biaggi <lbjanuario@gmail.com>
0003 /*
0004  * Firewalld backend for plasma firewall
0005  */
0006 #include "queryrulesfirewalldjob.h"
0007 #include <KLocalizedString>
0008 #include <QTimer>
0009 
0010 QueryRulesFirewalldJob::QueryRulesFirewalldJob()
0011 {
0012     m_simple = new FirewalldJob("getServices", {""}, FirewalldJob::SIMPLELIST);
0013     m_direct = new FirewalldJob("getAllRules");
0014 
0015     connect(m_direct, &KJob::result, this, [this](void) {
0016         m_directFinished = true;
0017 
0018         if (m_direct->error()) {
0019             setError(m_direct->error());
0020             setErrorText(m_direct->errorString());
0021             emitResult();
0022             return;
0023         }
0024 
0025         m_replyDirect = m_direct->getFirewalldreply();
0026         if (m_simpleFinished) {
0027             emitResult();
0028         }
0029     });
0030 
0031     connect(m_simple, &KJob::result, this, [this](void) {
0032         m_simpleFinished = true;
0033 
0034         if (m_simple->error()) {
0035             setError(m_simple->error());
0036             setErrorText(m_simple->errorString());
0037             emitResult();
0038             return;
0039         }
0040 
0041         m_replyServices = m_simple->getServices();
0042         if (m_directFinished) {
0043             emitResult();
0044         }
0045     });
0046 }
0047 
0048 QString QueryRulesFirewalldJob::name() const
0049 {
0050     return i18n("firewalld listing rules and services");
0051 }
0052 
0053 QList<firewalld_reply> QueryRulesFirewalldJob::getFirewalldreply() const
0054 {
0055     return m_replyDirect;
0056 }
0057 
0058 QStringList QueryRulesFirewalldJob::getServices() const
0059 {
0060     return m_replyServices;
0061 }
0062 
0063 void QueryRulesFirewalldJob::start()
0064 {
0065     m_direct->start();
0066     m_simple->start();
0067     return;
0068 }
0069 
0070 QueryRulesFirewalldJob::~QueryRulesFirewalldJob() = default;