VirtualBox

Changeset 87312 in vbox


Ignore:
Timestamp:
Jan 20, 2021 8:58:56 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9871: Network Manager: A bunch of changes for NAT network validation stuff; Make sure network name and CIDR are present and valid; Besides that, make sure network name isn't used by other networks.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r87306 r87312  
    19731973}
    19741974
     1975void UIMessageCenter::warnAboutNoNameSpecified(const QString &strName, QWidget *pParent /* = 0 */)
     1976{
     1977    alert(pParent, MessageType_Error,
     1978          tr("No new name specified for the NAT network previously called <b>%1</b>.").arg(strName));
     1979}
     1980
     1981void UIMessageCenter::warnAboutNameAlreadyBusy(const QString &strName, QWidget *pParent /* = 0 */)
     1982{
     1983    alert(pParent, MessageType_Error,
     1984          tr("The name <b>%1</b> is being used for several NAT networks.").arg(strName));
     1985}
     1986
     1987void UIMessageCenter::warnAboutNoCIDRSpecified(const QString &strName, QWidget *pParent /* = 0 */)
     1988{
     1989    alert(pParent, MessageType_Error,
     1990          tr("No CIDR specified for the NAT network <b>%1</b>.").arg(strName));
     1991}
     1992
     1993void UIMessageCenter::warnAboutInvalidCIDRSpecified(const QString &strCIDR, const QString &strName, QWidget *pParent /* = 0 */)
     1994{
     1995    alert(pParent, MessageType_Error,
     1996          tr("Invalid CIDR specified (<i>%1</i>) for the NAT network <b>%2</b>.").arg(strCIDR, strName));
     1997}
     1998
    19751999void UIMessageCenter::cannotAcquireCloudProviderManager(const CVirtualBox &comVBox, QWidget *pParent /* = 0 */) const
    19762000{
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r87306 r87312  
    409409    void cannotFindNATNetwork(const CVirtualBox &comVBox, const QString &strNetworkName, QWidget *pParent = 0) const;
    410410    void cannotRemoveNATNetwork(const CVirtualBox &comVBox, const QString &strNetworkName, QWidget *pParent = 0) const;
     411    void warnAboutNoNameSpecified(const QString &strName, QWidget *pParent = 0);
     412    void warnAboutNameAlreadyBusy(const QString &strName, QWidget *pParent = 0);
     413    void warnAboutNoCIDRSpecified(const QString &strName, QWidget *pParent = 0);
     414    void warnAboutInvalidCIDRSpecified(const QString &strCIDR, const QString &strName, QWidget *pParent = 0);
    411415
    412416    /* API: Cloud Profile Manager warnings: */
  • trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UIDetailsWidgetNATNetwork.cpp

    r87306 r87312  
    3131#include "UIIconPool.h"
    3232#include "UIDetailsWidgetNATNetwork.h"
     33#include "UIMessageCenter.h"
    3334#include "UINetworkManagerUtils.h"
    3435
     
    6162}
    6263
    63 void UIDetailsWidgetNATNetwork::setData(const UIDataNATNetwork &data, bool fHoldPosition /* = false */)
     64void UIDetailsWidgetNATNetwork::setData(const UIDataNATNetwork &data,
     65                                        const QStringList &busyNames /* = QStringList() */,
     66                                        bool fHoldPosition /* = false */)
    6467{
    6568    /* Cache old/new data: */
    6669    m_oldData = data;
    6770    m_newData = m_oldData;
     71    m_busyNames = busyNames;
    6872    m_fHoldPosition = fHoldPosition;
    6973
     
    7680bool UIDetailsWidgetNATNetwork::revalidate() const
    7781{
     82    /* Make sure network name isn't empty: */
     83    if (m_newData.m_strName.isEmpty())
     84    {
     85        msgCenter().warnAboutNoNameSpecified(m_oldData.m_strName);
     86        return false;
     87    }
     88    else
     89    {
     90        /* Make sure item names are unique: */
     91        if (m_busyNames.contains(m_newData.m_strName))
     92        {
     93            msgCenter().warnAboutNameAlreadyBusy(m_newData.m_strName);
     94            return false;
     95        }
     96    }
     97
     98    /* Make sure network CIDR isn't empty: */
     99    if (m_newData.m_strCIDR.isEmpty())
     100    {
     101        msgCenter().warnAboutNoCIDRSpecified(m_newData.m_strName);
     102        return false;
     103    }
     104    else
     105    {
     106        /* Make sure network CIDR is valid: */
     107        RTNETADDRIPV4 network, mask;
     108        const int rc = RTCidrStrToIPv4(m_newData.m_strCIDR.toUtf8().constData(), &network, &mask);
     109        if (RT_FAILURE(rc))
     110        {
     111            msgCenter().warnAboutInvalidCIDRSpecified(m_newData.m_strCIDR, m_newData.m_strName);
     112            return false;
     113        }
     114    }
     115
     116    /* Validate 'Forwarding' tab content: */
    78117    return m_pForwardingTableIPv4->validate() && m_pForwardingTableIPv6->validate();
    79118}
  • trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UIDetailsWidgetNATNetwork.h

    r87306 r87312  
    121121    const UIDataNATNetwork &data() const { return m_newData; }
    122122    /** Defines the host network @a data.
     123      * @param  busyNames      Holds the list of names busy by other
     124      *                        NAT networks.
    123125      * @param  fHoldPosition  Holds whether we should try to keep
    124126      *                        port forwarding rule position intact. */
    125     void setData(const UIDataNATNetwork &data, bool fHoldPosition = false);
     127    void setData(const UIDataNATNetwork &data,
     128                 const QStringList &busyNames = QStringList(),
     129                 bool fHoldPosition = false);
    126130
    127131    /** @name Change handling stuff.
     
    237241        /** Holds the 'Forwarding' button-box instance. */
    238242        QIDialogButtonBox     *m_pButtonBoxForwarding;
     243        /** Holds the list of names busy by other
     244          * NAT networks. */
     245        QStringList            m_busyNames;
    239246        /** Holds whether we should try to keep
    240247          * port forwarding rule position intact. */
  • trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UINetworkManager.cpp

    r87306 r87312  
    10691069    /* If there is an item => update details data: */
    10701070    if (pItem)
    1071         m_pDetailsWidgetNATNetwork->setData(*pItem, fHoldPosition);
     1071    {
     1072        QStringList busyNamesForItem = busyNames();
     1073        busyNamesForItem.removeAll(pItem->name());
     1074        m_pDetailsWidgetNATNetwork->setData(*pItem, busyNamesForItem, fHoldPosition);
     1075    }
    10721076    /* Otherwise => clear details: */
    10731077    else
     
    17371741}
    17381742
     1743QStringList UINetworkManagerWidget::busyNames() const
     1744{
     1745    QStringList names;
     1746    for (int i = 0; i < m_pTreeWidgetNATNetwork->topLevelItemCount(); ++i)
     1747    {
     1748        UIItemNATNetwork *pItem = qobject_cast<UIItemNATNetwork*>(m_pTreeWidgetNATNetwork->childItem(i));
     1749        const QString strItemName(pItem->name());
     1750        if (!strItemName.isEmpty() && !names.contains(strItemName))
     1751            names << strItemName;
     1752    }
     1753    return names;
     1754}
     1755
    17391756
    17401757/*********************************************************************************************************************************
  • trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UINetworkManager.h

    r87295 r87312  
    208208        /** Updates passed NAT network tree-widget item on the basis of passed @a data, @a fChooseItem if requested. */
    209209        void updateItemForNATNetwork(const UIDataNATNetwork &data, bool fChooseItem, UIItemNATNetwork *pItem);
     210
     211        /** Returns a list of busy NAT network names. */
     212        QStringList busyNames() const;
    210213    /** @} */
    211214
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette