diff --git a/autotests/settings/CMakeLists.txt b/autotests/settings/CMakeLists.txt index 9e3db57..b727e18 100644 --- a/autotests/settings/CMakeLists.txt +++ b/autotests/settings/CMakeLists.txt @@ -1,40 +1,42 @@ macro(NETWORKMANAGERQT_AUTOTESTS) foreach(_testname ${ARGN}) ecm_add_test(${_testname}.cpp LINK_LIBRARIES Qt5::Test KF5NetworkManagerQt_static) endforeach(_testname) endmacro(NETWORKMANAGERQT_AUTOTESTS) NETWORKMANAGERQT_AUTOTESTS( 8021xsettingtest adslsettingtest bluetoothsettingtest bondsettingtest bridgesettingtest bridgeportsettingtest cdmasettingtest connectionsettingtest gsmsettingtest infinibandsettingtest iptunnelsettingtest ipv4settingtest ipv6settingtest + matchsettingtest olpcmeshsettingtest ovsbridgesettingtest ovsinterfacesettingtest ovspatchsettingtest ovsportsettingtest pppsettingtest pppoesettingtest proxysettingtest serialsettingtest tunsettingtest + tcsettingtest usersettingtest vlansettingtest vxlansettingtest vpnsettingtest wimaxsettingtest wiredsettingtest wirelesssettingtest wirelesssecuritysettingtest ) diff --git a/autotests/settings/matchsettingtest.cpp b/autotests/settings/matchsettingtest.cpp new file mode 100644 index 0000000..bc89325 --- /dev/null +++ b/autotests/settings/matchsettingtest.cpp @@ -0,0 +1,63 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "matchsettingtest.h" + +#include "settings/matchsetting.h" + +#include + +#include + +#if !NM_CHECK_VERSION(1, 14, 0) +#define NM_SETTING_MATCH_INTERFACE_NAME "interface-name" +#endif + +void MatchSettingTest::testSetting_data() +{ + QTest::addColumn("interfaceName"); + + QTest::newRow("setting1") + << QStringList {QString("name1"), QString("name2")}; // interfaceName +} + +void MatchSettingTest::testSetting() +{ + QFETCH(QStringList, interfaceName); + + QVariantMap map; + + map.insert(QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME), interfaceName); + + NetworkManager::MatchSetting setting; + setting.fromMap(map); + + QVariantMap map1 = setting.toMap(); + + // Will fail if set some default values, because they are skipped in toMap() method + QVariantMap::const_iterator it = map.constBegin(); + while (it != map.constEnd()) { + QCOMPARE(it.value(), map1.value(it.key())); + ++it; + } +} + +QTEST_MAIN(MatchSettingTest) + diff --git a/autotests/settings/matchsettingtest.h b/autotests/settings/matchsettingtest.h new file mode 100644 index 0000000..c38368a --- /dev/null +++ b/autotests/settings/matchsettingtest.h @@ -0,0 +1,36 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_MATCHSETTING_TEST_H +#define NETWORKMANAGERQT_MATCHSETTING_TEST_H + +#include + +class MatchSettingTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testSetting_data(); + void testSetting(); +}; + +#endif // NETWORKMANAGERQT_MATCHSETTING_TEST_H + diff --git a/autotests/settings/tcsettingtest.cpp b/autotests/settings/tcsettingtest.cpp new file mode 100644 index 0000000..68d2a80 --- /dev/null +++ b/autotests/settings/tcsettingtest.cpp @@ -0,0 +1,104 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "tcsettingtest.h" + +#include "settings/tcsetting.h" + +#include + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_TC_CONFIG_QDISCS "qdiscs" +#define NM_SETTING_TC_CONFIG_TFILTERS "tfilters" +#endif + +void TcSettingTest::testSetting_data() +{ + QTest::addColumn("qdiscs"); + QTest::addColumn("tfilters"); + + NMVariantMapList qdiscs; + QVariantMap qdisc; + qdisc["one"] = "1"; + qdisc["two"] = 2; + qdiscs.append(qdisc); + + NMVariantMapList tfilters; + QVariantMap tfilter; + tfilter["three"] = "3"; + tfilter["four"] = 4; + tfilters.append(tfilter); + + QTest::newRow("setting1") + << qdiscs // qdiscs + << tfilters; // tfilters +} + +void TcSettingTest::testSetting() +{ + QFETCH(NMVariantMapList, tfilters); + QFETCH(NMVariantMapList, qdiscs); + + QVariantMap map; + + map.insert(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS), QVariant::fromValue(tfilters)); + map.insert(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS), QVariant::fromValue(qdiscs)); + + NetworkManager::TcSetting setting; + setting.fromMap(map); + + QVariantMap map1 = setting.toMap(); + + QVariantMap::const_iterator it = map.constBegin(); + while (it != map.constEnd()) { + NMVariantMapList list = it.value().value(); + NMVariantMapList list1 = map1.value(it.key()).value(); + + QCOMPARE(list.count(), list1.count()); + + int comparedMaps = 0; + for (int i = 0; i < list.size(); ++i) { + QVariantMap varMap = list.at(i); + for (int j = 0; j < list1.size(); ++j) { + QVariantMap varMap1 = list1.at(i); + QVariantMap::const_iterator ite = varMap.constBegin(); + int comparedvals = 0; + while (ite != varMap.constEnd()) { + QVariantMap::const_iterator val1 = varMap1.constFind(ite.key()); + if (val1 != varMap1.constEnd()) { + if (varMap.value(ite.key()) == val1.value()) { + ++comparedvals; + } + } + ++ite; + } + if (comparedvals == varMap.size()) { + comparedMaps++; + } + } + } + ++it; + QCOMPARE(comparedMaps, list.count()); + } +} + +QTEST_MAIN(TcSettingTest) diff --git a/autotests/settings/tcsettingtest.h b/autotests/settings/tcsettingtest.h new file mode 100644 index 0000000..df6ebbf --- /dev/null +++ b/autotests/settings/tcsettingtest.h @@ -0,0 +1,36 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_TC_SETTING_TEST_H +#define NETWORKMANAGERQT_TC_SETTING_TEST_H + +#include + +class TcSettingTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testSetting_data(); + void testSetting(); +}; + +#endif // NETWORKMANAGERQT_TC_SETTING_TEST_H + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd1b8a7..f75a874 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,284 +1,286 @@ # add_subdirectory(dbus) include_directories( ${NETWORKMANAGER_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/dbus ${CMAKE_CURRENT_SOURCE_DIR}/settings ) set(NetworkManagerQt_PART_SRCS device.cpp accesspoint.cpp activeconnection.cpp adsldevice.cpp bluetoothdevice.cpp bonddevice.cpp bridgedevice.cpp connection.cpp dhcp4config.cpp dhcp6config.cpp devicestatistics.cpp dnsconfiguration.cpp dnsdomain.cpp infinibanddevice.cpp ipaddress.cpp iproute.cpp ipconfig.cpp manager.cpp modemdevice.cpp olpcmeshdevice.cpp secretagent.cpp settings.cpp utils.cpp vlandevice.cpp vpnconnection.cpp vpnplugin.cpp wimaxdevice.cpp wimaxnsp.cpp wireddevice.cpp wirelessdevice.cpp wirelessnetwork.cpp generictypes.cpp genericdevice.cpp gredevice.cpp iptunneldevice.cpp macvlandevice.cpp teamdevice.cpp tundevice.cpp vethdevice.cpp wimaxdevice.cpp wimaxnsp.cpp ) set(NetworkManagerQt_SETTINGS_SRCS settings/adslsetting.cpp settings/bluetoothsetting.cpp settings/bondsetting.cpp settings/bridgesetting.cpp settings/bridgeportsetting.cpp settings/cdmasetting.cpp settings/connectionsettings.cpp settings/gsmsetting.cpp settings/iptunnelsetting.cpp settings/ipv4setting.cpp settings/ipv6setting.cpp settings/infinibandsetting.cpp + settings/matchsetting.cpp settings/olpcmeshsetting.cpp settings/ovsbridgesetting.cpp settings/ovsinterfacesetting.cpp settings/ovspatchsetting.cpp settings/ovsportsetting.cpp settings/pppsetting.cpp settings/pppoesetting.cpp settings/proxysetting.cpp settings/setting.cpp settings/serialsetting.cpp settings/security8021xsetting.cpp #settings/template.cpp settings/vlansetting.cpp settings/vpnsetting.cpp settings/wimaxsetting.cpp settings/wiredsetting.cpp settings/wirelesssetting.cpp settings/wirelesssecuritysetting.cpp settings/teamsetting.cpp + settings/tcsetting.cpp settings/genericsetting.cpp settings/tunsetting.cpp settings/usersetting.cpp settings/vxlansetting.cpp ) set(DBUS_INTERFACE_SRCS dbus/accesspointinterface.cpp dbus/activeconnectioninterface.cpp dbus/adsldeviceinterface.cpp dbus/agentmanagerinterface.cpp dbus/bluetoothdeviceinterface.cpp dbus/bonddeviceinterface.cpp dbus/bridgedeviceinterface.cpp dbus/connectioninterface.cpp dbus/deviceinterface.cpp dbus/devicestatisticsinterface.cpp dbus/dhcp4configinterface.cpp dbus/dhcp6configinterface.cpp dbus/dnsmanagerinterface.cpp dbus/genericdeviceinterface.cpp dbus/gredeviceinterface.cpp dbus/checkpointinterface.cpp dbus/infinibanddeviceinterface.cpp dbus/iptunneldeviceinterface.cpp dbus/ip4configinterface.cpp dbus/ip6configinterface.cpp dbus/macsecdeviceinterface.cpp dbus/macvlandeviceinterface.cpp dbus/modemdeviceinterface.cpp dbus/networkmanagerinterface.cpp dbus/olpcmeshdeviceinterface.cpp dbus/pppinterface.cpp dbus/secretagentadaptor.cpp dbus/settingsinterface.cpp dbus/teamdeviceinterface.cpp dbus/tundeviceinterface.cpp dbus/vethdeviceinterface.cpp dbus/vlandeviceinterface.cpp dbus/vpnconnectioninterface.cpp dbus/vpnplugininterface.cpp dbus/vxlandeviceinterface.cpp dbus/wimaxdeviceinterface.cpp dbus/wimaxnspinterface.cpp dbus/wireddeviceinterface.cpp dbus/wirelessdeviceinterface.cpp ) add_library(KF5NetworkManagerQt SHARED ${NetworkManagerQt_PART_SRCS} ${NetworkManagerQt_SETTINGS_SRCS} ${DBUS_INTERFACE_SRCS}) generate_export_header(KF5NetworkManagerQt EXPORT_FILE_NAME ${NetworkManagerQt_BINARY_DIR}/networkmanagerqt/networkmanagerqt_export.h BASE_NAME NetworkManagerQt) add_library(KF5::NetworkManagerQt ALIAS KF5NetworkManagerQt) target_include_directories(KF5NetworkManagerQt INTERFACE "$") # for examples to build target_include_directories(KF5NetworkManagerQt PUBLIC "$") target_link_libraries(KF5NetworkManagerQt PUBLIC Qt5::Core Qt5::Network Qt5::DBus) set_target_properties(KF5NetworkManagerQt PROPERTIES VERSION ${NETWORKMANAGERQT_VERSION_STRING} SOVERSION ${NETWORKMANAGERQT_SOVERSION} EXPORT_NAME NetworkManagerQt ) if (${NETWORKMANAGER_VERSION} VERSION_EQUAL 1.0.0 OR ${NETWORKMANAGER_VERSION} VERSION_GREATER 1.0.0) target_include_directories(KF5NetworkManagerQt PUBLIC ${NM-CORE_INCLUDE_DIRS}) else() target_include_directories(KF5NetworkManagerQt PUBLIC ${NETWORKMANAGER_INCLUDE_DIRS} SYSTEM PUBLIC ${NM-UTIL_INCLUDE_DIRS} ${NM-GLIB_INCLUDE_DIRS}) endif() ########### static lib for tests ############### add_library(KF5NetworkManagerQt_static STATIC ${NetworkManagerQt_PART_SRCS} ${NetworkManagerQt_SETTINGS_SRCS} ${DBUS_INTERFACE_SRCS}) set_target_properties(KF5NetworkManagerQt_static PROPERTIES COMPILE_FLAGS -DNMQT_STATIC=1) target_link_libraries(KF5NetworkManagerQt_static PUBLIC Qt5::Core Qt5::Network Qt5::DBus) target_include_directories(KF5NetworkManagerQt_static PUBLIC "$") ecm_generate_headers(NetworkManagerQt_CamelCase_HEADERS HEADER_NAMES AccessPoint ActiveConnection AdslDevice BluetoothDevice BondDevice BridgeDevice Connection Device DeviceStatistics Dhcp4Config Dhcp6Config DnsConfiguration DnsDomain GenericDevice GenericTypes GreDevice InfinibandDevice IpAddress IpConfig IpRoute IpTunnelDevice MacVlanDevice Manager ModemDevice OlpcMeshDevice SecretAgent Settings TeamDevice TunDevice Utils VethDevice VlanDevice VpnConnection VpnPlugin WimaxDevice WimaxNsp WiredDevice WirelessDevice WirelessNetwork REQUIRED_HEADERS NetworkManagerQt_HEADERS PREFIX NetworkManagerQt ) ecm_generate_headers(NetworkManagerQt_SETTINGS_CamelCase_HEADERS HEADER_NAMES AdslSetting BluetoothSetting BondSetting BridgeSetting BridgePortSetting CdmaSetting ConnectionSettings GsmSetting GenericSetting InfinibandSetting IpTunnelSetting Ipv4Setting Ipv6Setting OlpcMeshSetting PppoeSetting PppSetting Security8021xSetting SerialSetting Setting TeamSetting TunSetting VlanSetting VpnSetting WimaxSetting WiredSetting WirelessSecuritySetting WirelessSetting RELATIVE settings REQUIRED_HEADERS NetworkManagerQt_SETTINGS_HEADERS PREFIX NetworkManagerQt ) install(TARGETS KF5NetworkManagerQt EXPORT KF5NetworkManagerQtTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${NetworkManagerQt_CamelCase_HEADERS} ${NetworkManagerQt_SETTINGS_CamelCase_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/NetworkManagerQt/NetworkManagerQt COMPONENT Devel ) install(FILES ${NetworkManagerQt_BINARY_DIR}/networkmanagerqt/networkmanagerqt_export.h ${NetworkManagerQt_HEADERS} ${NetworkManagerQt_SETTINGS_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/NetworkManagerQt/networkmanagerqt COMPONENT Devel ) if(BUILD_QCH) ecm_add_qch( KF5NetworkManagerQt_QCH NAME NetworkManagerQt BASE_NAME KF5NetworkManagerQt VERSION ${KF5_VERSION} ORG_DOMAIN org.kde SOURCES # using only public headers, to cover only public API ${NetworkManagerQt_HEADERS} ${NetworkManagerQt_SETTINGS_HEADERS} MD_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md" LINK_QCHS Qt5Core_QCH Qt5Network_QCH Qt5DBus_QCH BLANK_MACROS NETWORKMANAGERQT_EXPORT NETWORKMANAGERQT_DEPRECATED NETWORKMANAGERQT_DEPRECATED_EXPORT TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} COMPONENT Devel ) endif() include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME NetworkManagerQt LIB_NAME KF5NetworkManagerQt DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/NetworkManagerQt) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/settings/matchsetting.cpp b/src/settings/matchsetting.cpp new file mode 100644 index 0000000..2275b18 --- /dev/null +++ b/src/settings/matchsetting.cpp @@ -0,0 +1,99 @@ +/* + Copyright Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "matchsetting.h" +#include "matchsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 14, 0) +#define NM_SETTING_MATCH_SETTING_NAME "match" +#define NM_SETTING_MATCH_INTERFACE_NAME "interface-name" +#endif + +NetworkManager::MatchSettingPrivate::MatchSettingPrivate() + : name(NM_SETTING_MATCH_SETTING_NAME) +{ } + +NetworkManager::MatchSetting::MatchSetting() + : Setting(Setting::Match) + , d_ptr(new MatchSettingPrivate()) +{ } + +NetworkManager::MatchSetting::MatchSetting(const Ptr &other) + : Setting(other) + , d_ptr(new MatchSettingPrivate()) +{ + setInterfaceName(other->interfaceName()); +} + +NetworkManager::MatchSetting::~MatchSetting() +{ + delete d_ptr; +} + +QString NetworkManager::MatchSetting::name() const +{ + Q_D(const MatchSetting); + + return d->name; +} + +void NetworkManager::MatchSetting::setInterfaceName(const QStringList &name) +{ + Q_D(MatchSetting); + + d->interfaceName = name; +} + +QStringList NetworkManager::MatchSetting::interfaceName() const +{ + Q_D(const MatchSetting); + + return d->interfaceName; +} + +void NetworkManager::MatchSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME))) { + setInterfaceName(setting.value(QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME)).toStringList()); + } +} + +QVariantMap NetworkManager::MatchSetting::toMap() const +{ + QVariantMap setting; + + if (!interfaceName().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME), interfaceName()); + } + + return setting; +} + +QDebug NetworkManager::operator <<(QDebug dbg, const NetworkManager::MatchSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_MATCH_INTERFACE_NAME << ": " << setting.interfaceName() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/src/settings/matchsetting.h b/src/settings/matchsetting.h new file mode 100644 index 0000000..62498d0 --- /dev/null +++ b/src/settings/matchsetting.h @@ -0,0 +1,66 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_MATCH_SETTING_H +#define NETWORKMANAGERQT_MATCH_SETTING_H + +#include +#include "setting.h" + +namespace NetworkManager +{ + +class MatchSettingPrivate; + +/** + * Represents Match setting + */ +class NETWORKMANAGERQT_EXPORT MatchSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + MatchSetting(); + explicit MatchSetting(const Ptr &other); + ~MatchSetting() override; + + QString name() const override; + + void setInterfaceName(const QStringList &name); + QStringList interfaceName() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + MatchSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(MatchSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const MatchSetting &setting); + +} + +#endif // NETWORKMANAGERQT_MATCH_SETTING_H + diff --git a/src/settings/matchsetting_p.h b/src/settings/matchsetting_p.h new file mode 100644 index 0000000..2040b2c --- /dev/null +++ b/src/settings/matchsetting_p.h @@ -0,0 +1,42 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_MATCH_SETTING_P_H +#define NETWORKMANAGERQT_MATCH_SETTING_P_H + +#include + +namespace NetworkManager +{ + +class MatchSettingPrivate +{ +public: + MatchSettingPrivate(); + + QString name; + + QStringList interfaceName; +}; + +} + +#endif // NETWORKMANAGERQT_MATCH_SETTING_P_H + diff --git a/src/settings/setting.cpp b/src/settings/setting.cpp index 04d2729..177ed39 100644 --- a/src/settings/setting.cpp +++ b/src/settings/setting.cpp @@ -1,331 +1,346 @@ /* Copyright 2012-2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "setting.h" #undef signals #include #include #define signals Q_SIGNALS #include +#if !NM_CHECK_VERSION(1, 14, 0) +#define NM_SETTING_MATCH_SETTING_NAME "match" +#endif + #if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_TC_CONFIG_SETTING_NAME "tc" #define NM_SETTING_OVS_BRIDGE_SETTING_NAME "ovs-bridge" #define NM_SETTING_OVS_INTERFACE_SETTING_NAME "ovs-interface" #define NM_SETTING_OVS_PATCH_SETTING_NAME "ovs-patch" #define NM_SETTING_OVS_PORT_SETTING_NAME "ovs-port" #endif #if !NM_CHECK_VERSION(1, 8, 0) #define NM_SETTING_USER_SETTING_NAME "user" #endif #if !NM_CHECK_VERSION(1, 6, 0) #define NM_SETTING_PROXY_SETTING_NAME "proxy" #endif namespace NetworkManager { class SettingPrivate { public: SettingPrivate(); Setting::SettingType type; bool initialized; }; QDebug operator <<(QDebug dbg, const Setting &setting) { dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; return dbg.maybeSpace(); } } NetworkManager::SettingPrivate::SettingPrivate(): type(Setting::Wired), initialized(false) { } QString NetworkManager::Setting::typeAsString(NetworkManager::Setting::SettingType type) { QString typeString; switch (type) { case Cdma: typeString = QLatin1String(NM_SETTING_CDMA_SETTING_NAME); break; case Gsm: typeString = QLatin1String(NM_SETTING_GSM_SETTING_NAME); break; case Bluetooth: typeString = QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME); break; case Ipv4: typeString = QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME); break; case Ipv6: typeString = QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME); break; case Ppp: typeString = QLatin1String(NM_SETTING_PPP_SETTING_NAME); break; case Pppoe: typeString = QLatin1String(NM_SETTING_PPPOE_SETTING_NAME); break; case Security8021x: typeString = QLatin1String(NM_SETTING_802_1X_SETTING_NAME); break; case Serial: typeString = QLatin1String(NM_SETTING_SERIAL_SETTING_NAME); break; case Vpn: typeString = QLatin1String(NM_SETTING_VPN_SETTING_NAME); break; case Wired: typeString = QLatin1String(NM_SETTING_WIRED_SETTING_NAME); break; case Wireless: typeString = QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME); break; case WirelessSecurity: typeString = QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); break; case OlpcMesh: typeString = QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME); break; case Vlan: typeString = QLatin1String(NM_SETTING_VLAN_SETTING_NAME); break; case Wimax: typeString = QLatin1String(NM_SETTING_WIMAX_SETTING_NAME); break; case Bond: typeString = QLatin1String(NM_SETTING_BOND_SETTING_NAME); break; case Bridge: typeString = QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME); break; case Team: typeString = QLatin1String(NM_SETTING_TEAM_SETTING_NAME); break; case Vxlan: typeString = QLatin1String(NM_SETTING_VXLAN_SETTING_NAME); break; case IpTunnel: typeString = QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME); break; case Proxy: typeString = QLatin1String(NM_SETTING_PROXY_SETTING_NAME); break; case User: typeString = QLatin1String(NM_SETTING_USER_SETTING_NAME); break; case OvsInterface: typeString = QLatin1String(NM_SETTING_OVS_INTERFACE_SETTING_NAME); break; case OvsBridge: typeString = QLatin1String(NM_SETTING_OVS_BRIDGE_SETTING_NAME); break; case OvsPatch: typeString = QLatin1String(NM_SETTING_OVS_PATCH_SETTING_NAME); break; case OvsPort: typeString = QLatin1String(NM_SETTING_OVS_PORT_SETTING_NAME); break; + case Match: + typeString = QLatin1String(NM_SETTING_MATCH_SETTING_NAME); + break; + case Tc: + typeString = QLatin1String(NM_SETTING_TC_CONFIG_SETTING_NAME); + break; case NetworkManager::Setting::Generic: typeString = QLatin1String(NM_SETTING_GENERIC_SETTING_NAME); break; default: break; } return typeString; } NetworkManager::Setting::SettingType NetworkManager::Setting::typeFromString(const QString &typeString) { SettingType type = Wired; if (typeString == QLatin1String(NM_SETTING_CDMA_SETTING_NAME)) { type = Cdma; } else if (typeString == QLatin1String(NM_SETTING_GSM_SETTING_NAME)) { type = Gsm; } else if (typeString == QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME)) { type = Bluetooth; } else if (typeString == QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME)) { type = Ipv4; } else if (typeString == QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME)) { type = Ipv6; } else if (typeString == QLatin1String(NM_SETTING_PPP_SETTING_NAME)) { type = Ppp; } else if (typeString == QLatin1String(NM_SETTING_PPPOE_SETTING_NAME)) { type = Pppoe; } else if (typeString == QLatin1String(NM_SETTING_SERIAL_SETTING_NAME)) { type = Serial; } else if (typeString == QLatin1String(NM_SETTING_802_1X_SETTING_NAME)) { type = Security8021x; } else if (typeString == QLatin1String(NM_SETTING_VPN_SETTING_NAME)) { type = Vpn; } else if (typeString == QLatin1String(NM_SETTING_WIRED_SETTING_NAME)) { type = Wired; } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME)) { type = Wireless; } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) { type = WirelessSecurity; } else if (typeString == QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME)) { type = OlpcMesh; } else if (typeString == QLatin1String(NM_SETTING_VLAN_SETTING_NAME)) { type = Vlan; } else if (typeString == QLatin1String(NM_SETTING_WIMAX_SETTING_NAME)) { type = Wimax; } else if (typeString == QLatin1String(NM_SETTING_BOND_SETTING_NAME)) { type = Bond; } else if (typeString == QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME)) { type = Bridge; } else if (typeString == QLatin1String(NM_SETTING_TEAM_SETTING_NAME)) { type = Team; } else if (typeString == QLatin1String(NM_SETTING_VXLAN_SETTING_NAME)) { type = Vxlan; } else if (typeString == QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME)) { type = IpTunnel; } else if (typeString == QLatin1String(NM_SETTING_GENERIC_SETTING_NAME)) { type = Generic; } else if (typeString == QLatin1String(NM_SETTING_USER_SETTING_NAME)) { type = User; } else if (typeString == QLatin1String(NM_SETTING_PROXY_SETTING_NAME)) { type = Proxy; } else if (typeString == QLatin1String(NM_SETTING_OVS_INTERFACE_SETTING_NAME)) { type = OvsInterface; } else if (typeString == QLatin1String(NM_SETTING_OVS_BRIDGE_SETTING_NAME)) { type = OvsBridge; } else if (typeString == QLatin1String(NM_SETTING_OVS_PATCH_SETTING_NAME)) { type = OvsPatch; } else if (typeString == QLatin1String(NM_SETTING_OVS_PORT_SETTING_NAME)) { type = OvsPort; + } else if (typeString == QLatin1String(NM_SETTING_MATCH_SETTING_NAME)) { + type = Match; + } else if (typeString == QLatin1String(NM_SETTING_TC_CONFIG_SETTING_NAME)) { + type = Tc; } return type; } NetworkManager::Setting::Setting(SettingType type) : d_ptr(new SettingPrivate()) { setType(type); } NetworkManager::Setting::Setting(const NetworkManager::Setting::Ptr &setting) : d_ptr(new SettingPrivate()) { setInitialized(!setting->isNull()); setType(setting->type()); } NetworkManager::Setting::~Setting() { delete d_ptr; } void NetworkManager::Setting::fromMap(const QVariantMap &map) { Q_UNUSED(map); } QVariantMap NetworkManager::Setting::toMap() const { return QVariantMap(); } QStringList NetworkManager::Setting::needSecrets(bool requestNew) const { Q_UNUSED(requestNew); return QStringList(); } QString NetworkManager::Setting::name() const { return QString(); } void NetworkManager::Setting::secretsFromMap(const QVariantMap &map) { Q_UNUSED(map); } void NetworkManager::Setting::secretsFromStringMap(const NMStringMap &map) { QVariantMap secretsMap; NMStringMap::ConstIterator i = map.constBegin(); while (i != map.constEnd()) { secretsMap.insert(i.key(), i.value()); ++i; } secretsFromMap(secretsMap); } QVariantMap NetworkManager::Setting::secretsToMap() const { return QVariantMap(); } NMStringMap NetworkManager::Setting::secretsToStringMap() const { NMStringMap ret; QVariantMap secretsMap = secretsToMap(); QVariantMap::ConstIterator i = secretsMap.constBegin(); while (i != secretsMap.constEnd()) { ret.insert(i.key(), i.value().toString()); ++i; } return ret; } void NetworkManager::Setting::setInitialized(bool initialized) { Q_D(Setting); d->initialized = initialized; } bool NetworkManager::Setting::isNull() const { Q_D(const Setting); return !d->initialized; } void NetworkManager::Setting::setType(NetworkManager::Setting::SettingType type) { Q_D(Setting); d->type = type; } NetworkManager::Setting::SettingType NetworkManager::Setting::type() const { Q_D(const Setting); return d->type; } diff --git a/src/settings/setting.h b/src/settings/setting.h index 87d4afe..43b5d79 100644 --- a/src/settings/setting.h +++ b/src/settings/setting.h @@ -1,160 +1,162 @@ /* Copyright 2012-2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef NETWORKMANAGERQT_SETTING_H #define NETWORKMANAGERQT_SETTING_H #include #include "generictypes.h" #undef signals #include #define signals Q_SIGNALS #include #include #include #include namespace NetworkManager { class SettingPrivate; /** * Base class for all kinds of setting */ class NETWORKMANAGERQT_EXPORT Setting { public: typedef QSharedPointer Ptr; typedef QList List; enum SettingType { Adsl, Cdma, Gsm, Infiniband, Ipv4, Ipv6, Ppp, Pppoe, Security8021x, Serial, Vpn, Wired, Wireless, WirelessSecurity, Bluetooth, OlpcMesh, Vlan, Wimax, Bond, Bridge, BridgePort, Team, Generic, Tun, Vxlan, IpTunnel, Proxy, User, OvsBridge, OvsInterface, OvsPatch, - OvsPort + OvsPort, + Match, + Tc }; enum SecretFlagType { None = 0, AgentOwned = 0x01, NotSaved = 0x02, NotRequired = 0x04 }; Q_DECLARE_FLAGS(SecretFlags, SecretFlagType) enum MacAddressRandomization { MacAddressRandomizationDefault = 0, MacAddressRandomizationNever, MacAddressRandomizationAlways }; static QString typeAsString(SettingType type); static SettingType typeFromString(const QString &type); explicit Setting(SettingType type); explicit Setting(const Ptr &setting); virtual ~Setting(); /** * @brief Must be reimplemented, default implementation does nothing */ virtual void fromMap(const QVariantMap &map); /** * @brief Must be reimplemented, default implementationd does nothing */ virtual QVariantMap toMap() const; virtual void secretsFromMap(const QVariantMap &map); /** * @brief secretsFromStringMap is a convenience function * to set the secrets from a map of strings. * @param map to extract secrets from */ virtual void secretsFromStringMap(const NMStringMap &map); virtual QVariantMap secretsToMap() const; /** * @brief secretsToStringMap is a convenience function * to get the secrets to map of strings. * @return string map with current secrets */ virtual NMStringMap secretsToStringMap() const; virtual QStringList needSecrets(bool requestNew = false) const; /** * @brief Must be reimplemented, default implementationd does nothing */ virtual QString name() const; void setInitialized(bool initialized); bool isNull() const; void setType(SettingType type); SettingType type() const; protected: SettingPrivate *d_ptr; private: Q_DECLARE_PRIVATE(Setting) }; Q_DECLARE_OPERATORS_FOR_FLAGS(Setting::SecretFlags) NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const Setting &setting); } #endif // NETWORKMANAGERQT_SETTING_H diff --git a/src/settings/tcsetting.cpp b/src/settings/tcsetting.cpp new file mode 100644 index 0000000..56aa49d --- /dev/null +++ b/src/settings/tcsetting.cpp @@ -0,0 +1,138 @@ +/* + Copyright Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "tcsetting.h" +#include "tcsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_TC_CONFIG_SETTING_NAME "tc" + +#define NM_SETTING_TC_CONFIG_QDISCS "qdiscs" +#define NM_SETTING_TC_CONFIG_TFILTERS "tfilters" +#endif + +NetworkManager::TcSettingPrivate::TcSettingPrivate() + : name(NM_SETTING_TC_CONFIG_SETTING_NAME) +{ } + +NetworkManager::TcSetting::TcSetting() + : Setting(Setting::Tc) + , d_ptr(new TcSettingPrivate()) +{ } + +NetworkManager::TcSetting::TcSetting(const Ptr &other) + : Setting(other) + , d_ptr(new TcSettingPrivate()) +{ + setQdiscs(other->qdiscs()); + setTfilters(other->tfilters()); +} + +NetworkManager::TcSetting::~TcSetting() +{ + delete d_ptr; +} + +QString NetworkManager::TcSetting::name() const +{ + Q_D(const TcSetting); + + return d->name; +} + +void NetworkManager::TcSetting::setQdiscs(const NMVariantMapList &qdiscs) +{ + Q_D(TcSetting); + + d->qdiscs = qdiscs; +} + +NMVariantMapList NetworkManager::TcSetting::qdiscs() const +{ + Q_D(const TcSetting); + + return d->qdiscs; +} + +void NetworkManager::TcSetting::setTfilters(const NMVariantMapList &tfilters) +{ + Q_D(TcSetting); + + d->tfilters = tfilters; +} + +NMVariantMapList NetworkManager::TcSetting::tfilters() const +{ + Q_D(const TcSetting); + + return d->tfilters; +} + +void NetworkManager::TcSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS))) { + setQdiscs(qdbus_cast(setting.value(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS)))); + } + + if (setting.contains(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS))) { + setTfilters(qdbus_cast(setting.value(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS)))); + } +} + +QVariantMap NetworkManager::TcSetting::toMap() const +{ + QVariantMap setting; + + if (!qdiscs().empty()) { + setting.insert(QLatin1String(NM_SETTING_TC_CONFIG_QDISCS), QVariant::fromValue(qdiscs())); + } + + if (!tfilters().empty()) { + setting.insert(QLatin1String(NM_SETTING_TC_CONFIG_TFILTERS), QVariant::fromValue(tfilters())); + } + + return setting; +} + +QDebug NetworkManager::operator <<(QDebug dbg, const NetworkManager::TcSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_TC_CONFIG_QDISCS << ": " << '\n'; + Q_FOREACH (const QVariantMap & qdisc, setting.qdiscs()) { + QVariantMap::const_iterator i = qdisc.constBegin(); + while (i != qdisc.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + dbg.nospace() << NM_SETTING_TC_CONFIG_TFILTERS << ": " << '\n'; + Q_FOREACH (const QVariantMap & tfilter, setting.tfilters()) { + QVariantMap::const_iterator i = tfilter.constBegin(); + while (i != tfilter.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + + return dbg.maybeSpace(); +} + diff --git a/src/settings/tcsetting.h b/src/settings/tcsetting.h new file mode 100644 index 0000000..3c810ac --- /dev/null +++ b/src/settings/tcsetting.h @@ -0,0 +1,69 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_TC_SETTING_H +#define NETWORKMANAGERQT_TC_SETTING_H + +#include +#include "setting.h" + +namespace NetworkManager +{ + +class TcSettingPrivate; + +/** + * Represents Tc setting + */ +class NETWORKMANAGERQT_EXPORT TcSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + TcSetting(); + explicit TcSetting(const Ptr &other); + ~TcSetting() override; + + QString name() const override; + + void setQdiscs(const NMVariantMapList &qdiscs); + NMVariantMapList qdiscs() const; + + void setTfilters(const NMVariantMapList &tfilters); + NMVariantMapList tfilters() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + TcSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(TcSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const TcSetting &setting); + +} + +#endif // NETWORKMANAGERQT_TC_SETTING_H + diff --git a/src/settings/tcsetting_p.h b/src/settings/tcsetting_p.h new file mode 100644 index 0000000..454ffd5 --- /dev/null +++ b/src/settings/tcsetting_p.h @@ -0,0 +1,47 @@ +/* + Copyright 2018 Pranav Gade + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_TC_SETTING_P_H +#define NETWORKMANAGERQT_TC_SETTING_P_H + +#include + +#include + +typedef QList NMVariantMapList; + +namespace NetworkManager +{ + +class TcSettingPrivate +{ +public: + TcSettingPrivate(); + + QString name; + + NMVariantMapList qdiscs; + NMVariantMapList tfilters; +}; + +} + +#endif // NETWORKMANAGERQT_TC_SETTING_P_H +