1
0
mirror of https://github.com/fwbuilder/fwbuilder synced 2026-03-23 19:57:21 +01:00

2009-01-23 vadim <vadim@vk.crocodile.org>

* FindWhereUsedWidget.cpp (FindWhereUsedWidget::createQTWidgetItem):
        fixed bug #2412334: "feature request: where used ->
        directly". There has been a change in the "Where used" function in
        v3.0 compared to the implementation in v2.1. New version showed
        not only rule elements and groups that referred to the given
        object, but also found all groups that referred to other groups
        that referred to the given object. Such recursive action was not
        always obvious to the user and was inconvenient when the function
        was used to find all places where given object was used with the
        goal to replace it with some other object. This fix reverts to the
        old behavior where only direct usages are reported by the "Where
        used" function. Elements of UI in this function have also been
        cleaned up and further unified with confirmation dialog shown when
        user tries to delete an object that is used in some groups and
        rules.
This commit is contained in:
Vadim Kurland 2009-01-24 07:17:05 +00:00
parent f1dded95b3
commit ac34c6f2a1
12 changed files with 220 additions and 207 deletions

View File

@ -1 +1 @@
#define BUILD_NUM 746
#define BUILD_NUM 747

View File

@ -1,5 +1,21 @@
2009-01-23 vadim <vadim@vk.crocodile.org>
* FindWhereUsedWidget.cpp (FindWhereUsedWidget::createQTWidgetItem):
fixed bug #2412334: "feature request: where used ->
directly". There has been a change in the "Where used" function in
v3.0 compared to the implementation in v2.1. New version showed
not only rule elements and groups that referred to the given
object, but also found all groups that referred to other groups
that referred to the given object. Such recursive action was not
always obvious to the user and was inconvenient when the function
was used to find all places where given object was used with the
goal to replace it with some other object. This fix reverts to the
old behavior where only direct usages are reported by the "Where
used" function. Elements of UI in this function have also been
cleaned up and further unified with confirmation dialog shown when
user tries to delete an object that is used in some groups and
rules.
* PolicyCompiler_PrintRule.cpp (PrintRule::_printAddr): fixed bug
#2526173: "fwb_ipt crashes due to old-broadcast". This bug was
introduced when support for module iprange was sadded. Need

View File

@ -67,11 +67,6 @@ ConfirmDeleteObjectDialog::ConfirmDeleteObjectDialog(QWidget*p) : QDialog(p)
{
m_dialog = new Ui::ConfirmDeleteObjectDialog_q;
m_dialog->setupUi(this);
//QVBoxLayout *b=new QVBoxLayout((QWidget*)FrameForList);
//fwu = new FindWhereUsedWidget((QWidget*)FrameForList,0,0, true);
//b->addWidget(fwu);
//connect(objectsList, SIGNAL(selectionChanged(QListBoxItem *)), this, SLOT(listItemSelected(QListBoxItem *)));
}
ConfirmDeleteObjectDialog::~ConfirmDeleteObjectDialog()
@ -106,7 +101,8 @@ void ConfirmDeleteObjectDialog::findForObject(FWObject *obj)
QPixmapCache::insert( icn_file, pm0);
}
mw->db()->findWhereUsed(obj,mw->db(),resset);
mw->db()->findWhereObjectIsUsed(obj, mw->db(), resset);
FindWhereUsedWidget::humanizeSearchResults(resset);
if (fwbdebug)
{
@ -116,94 +112,31 @@ void ConfirmDeleteObjectDialog::findForObject(FWObject *obj)
}
set<FWObject*>::iterator i=resset.begin();
QTreeWidgetItem *item;
QString c1;
QString c2;
FWObject* o;
Rule* r;
RuleSet* rs;
FWObject* fw=NULL;
int itemCounter = 0;
for(;i!=resset.end();++i)
for (;i!=resset.end();++i)
{
o=*i;
fw=NULL;
r=NULL;
rs=NULL;
if (findRef(obj,o)==NULL) continue;
if (RuleElement::cast(o)!=NULL)
{
fw=o->getParent();
while (fw!=NULL && !Firewall::isA(fw))
{
if (Rule::cast(fw))
{
r=Rule::cast(fw);
} else if (RuleSet::cast(fw))
{
rs=RuleSet::cast(fw);
}
fw=fw->getParent();
}
if (fw==NULL || r==NULL || rs==NULL) continue;
c1=QString::fromUtf8(fw->getName().c_str());
if (NAT::isA(rs))
{
c2=tr("NAT");
} else if (Policy::isA(rs))
{
c2=tr("Policy");
} else if (Routing::isA(rs))
{
c2=tr("Routing");
} else
{
c2=tr("Unknown rule set");
}
c2+=tr("/Rule%1").arg(r->getPosition());
} else if (
mw->isSystem(o) ||
Rule::cast(o) ||
RuleSet::cast(o) ||
Firewall::cast(o) ||
Library::cast(o))
{
continue;
}
else
{
c1=QString::fromUtf8(o->getName().c_str());
c2=tr("Type: ")+QString::fromUtf8(o->getTypeName().c_str());
}
string icn="icon-tree";
// FWObject *pixobj=(fw==NULL)?o:fw;
// QPixmap pm = QPixmap::fromMimeSource(
// Resources::global_res->getObjResourceStr(pixobj, icn).c_str() );
QStringList qsl;
qsl << QString::fromUtf8( obj->getName().c_str()) << c1 << c2;
item = new QTreeWidgetItem(m_dialog->objectsView, qsl);
item->setIcon(0,QIcon(pm0));
FWObject* o = *i;
// one of the objects returned by findWhereObjectIsUsed is a group
// object <o> belongs to. We need to skip this group.
//if (findRef(obj,o)==NULL) continue;
QTreeWidgetItem *item = FindWhereUsedWidget::createQTWidgetItem(obj, o);
if (item==NULL) continue;
m_dialog->objectsView->addTopLevelItem(item);
itemCounter++;
}
if (itemCounter==0)
{
QStringList qsl;
qsl << QString::fromUtf8( obj->getName().c_str())
<< tr("Not used anywhere") << "";
item = new QTreeWidgetItem(m_dialog->objectsView, qsl);
qsl << QString::fromUtf8( obj->getName().c_str()) << ""
<< tr("Not used anywhere");
QTreeWidgetItem *item = new QTreeWidgetItem(m_dialog->objectsView, qsl);
item->setIcon(0,QIcon(pm0));
}
m_dialog->objectsView->resizeColumnToContents(0);
m_dialog->objectsView->resizeColumnToContents(1);
}

View File

@ -95,7 +95,7 @@ FindWhereUsedWidget::FindWhereUsedWidget(QWidget *p,
}
else
{
connect (m_widget->dropArea,SIGNAL(objectDeleted()),this,SLOT(init()));
connect(m_widget->dropArea,SIGNAL(objectDeleted()),this,SLOT(init()));
}
}
@ -111,12 +111,11 @@ void FindWhereUsedWidget::setShowObject(bool fl)
void FindWhereUsedWidget::itemActivated(QTreeWidgetItem* item)
{
FWObject *o;
o = mapping[item];
FWObject *container = (FWObject*)(qVariantValue<void*>(item->data(1, Qt::UserRole)));
if (flShowObject && o!=NULL)
if (flShowObject && container!=NULL)
{
showObject(o);
showObject(container);
}
}
@ -135,105 +134,40 @@ void FindWhereUsedWidget::_find(FWObject *obj)
{
object = obj;
m_widget->resListView->clear();
mapping.clear();
resset.clear();
if (fwbdebug) qDebug("FindWhereUsedWidget: initiate search for %s",
obj->getName().c_str());
mw->db()->findWhereUsed(obj, mw->db(), resset);
mw->db()->findWhereObjectIsUsed(obj, mw->db(), resset);
humanizeSearchResults(resset);
set<FWObject*>::iterator i=resset.begin();
QTreeWidgetItem *item;
QString c1;
QString c2;
FWObject* o;
Rule* r;
RuleSet* rs;
FWObject* fw=NULL;
for(;i!=resset.end();++i)
{
o=*i;
fw=NULL;
r=NULL;
rs=NULL;
for (;i!=resset.end();++i)
{
FWObject *o = *i;
if (fwbdebug) qDebug("Search result object id=%d type=%s name=%s",
o->getId(),
o->getTypeName().c_str(),
o->getName().c_str());
// if (findRef(object,o)==NULL) continue;
if (mw->isSystem(o) || RuleSet::cast(o) ||
Firewall::cast(o) || Library::cast(o)) continue;
c1 = QString::fromUtf8(o->getName().c_str());
c2 = tr("Type: ")+QString::fromUtf8(o->getTypeName().c_str());
if (RuleElement::cast(o)!=NULL || Rule::cast(o)!=NULL)
{
fw = o;
while (fw!=NULL && !Firewall::isA(fw))
{
if (Rule::cast(fw))
{
r=Rule::cast(fw);
} else if (RuleSet::cast(fw))
{
rs=RuleSet::cast(fw);
}
fw=fw->getParent();
}
if (fw==NULL || r==NULL || rs==NULL) continue;
c1 = QString::fromUtf8(fw->getName().c_str());
if (NAT::isA(rs))
{
c2=tr("NAT");
} else if (Policy::isA(rs))
{
c2=tr("Policy");
} else if (Routing::isA(rs))
{
c2=tr("Routing");
} else
{
c2=tr("Unknown rule set");
}
c2+=tr("/Rule%1").arg(r->getPosition());
}
FWObject *pixobj=(fw==NULL)?o:fw;
QString icn_file =
(":/Icons/"+pixobj->getTypeName()+"/icon-tree").c_str();
QPixmap pm;
if ( ! QPixmapCache::find( icn_file, pm) )
{
pm.load( icn_file );
QPixmapCache::insert( icn_file, pm);
}
QStringList qsl;
qsl << c1 << c2;
item = new QTreeWidgetItem(m_widget->resListView, qsl);
item->setIcon(0, QIcon(pm));
mapping[item] = o;
QTreeWidgetItem *item = createQTWidgetItem(obj, o);
if (item==NULL) continue;
m_widget->resListView->addTopLevelItem(item);
}
m_widget->resListView->resizeColumnToContents(0);
m_widget->resListView->resizeColumnToContents(1);
show();
}
void FindWhereUsedWidget::init()
{
object=NULL;
m_widget->resListView->clear();
mapping.clear();
resset.clear();
}
void FindWhereUsedWidget::findFromDrop()
@ -248,8 +182,6 @@ void FindWhereUsedWidget::showObject(FWObject* o)
if (object==NULL || o==NULL) return;
FWReference* ref = NULL;
if (RuleElement::cast(o)!=NULL)
{
mw->activeProject()->openRuleSet(o->getParent()->getParent());
@ -295,3 +227,113 @@ void FindWhereUsedWidget::showObject(FWObject* o)
//mw->closeEditor();
//mw->openObject( o );
}
void FindWhereUsedWidget::humanizeSearchResults(std::set<FWObject *> &resset)
{
set<FWObject*> tmp_res; // set deduplicates items automatically
set<FWObject*>::iterator i = resset.begin();
for (;i!=resset.end();++i)
{
FWReference *ref = FWReference::cast(*i);
if (ref)
{
FWObject *o = ref->getParent(); // NB! We need parent of this ref.
tmp_res.insert(o);
if (fwbdebug)
qDebug("humanizeSearchResults: adding %s (%s)",
o->getName().c_str(), o->getTypeName().c_str());
#if 0
if (RuleElement::cast(o)!=NULL)
{
tmp_res.insert(o->getParent()); // rule
continue;
}
if (Group::cast(o)!=NULL)
{
tmp_res.insert(o);
continue;
}
#endif
} else
tmp_res.insert(*i);
}
resset.clear();
resset = tmp_res;
}
QTreeWidgetItem* FindWhereUsedWidget::createQTWidgetItem(FWObject* o,
FWObject *container)
{
QString c1, c2;
FWObject *fw = NULL;
Rule *r = NULL;
RuleSet *rs = NULL;
QPixmap object_icon;
QPixmap parent_icon;
if (mw->isSystem(container) || Library::cast(container)) return NULL;
if (RuleElement::cast(container)!=NULL || Rule::cast(container)!=NULL)
{
fw = container;
while (fw!=NULL && !Firewall::isA(fw))
{
if (Rule::cast(fw)) r = Rule::cast(fw);
if (RuleSet::cast(fw)) rs = RuleSet::cast(fw);
fw = fw->getParent();
}
if (fw==NULL || r==NULL || rs==NULL) return NULL;
c1 = QString::fromUtf8(fw->getName().c_str());
QString ruleset_kind;
if (NAT::isA(rs))
{
ruleset_kind = tr("NAT rule set");
} else if (Policy::isA(rs))
{
ruleset_kind = tr("Policy rule set");
} else if (Routing::isA(rs))
{
ruleset_kind = tr("Routing rule set");
} else
{
ruleset_kind = tr("Rule set of unknown type");
}
QString rule_element_name;
if (RuleElement::cast(container)!=NULL)
rule_element_name = container->getTypeName().c_str();
if (Rule::cast(container)!=NULL)
rule_element_name = "Action";
c2 += tr("%1 \"%2\" / Rule %3 / %4").
arg(ruleset_kind).
arg(rs->getName().c_str()).
arg(Rule::cast(r)->getPosition()).
arg(rule_element_name);
loadIcon(parent_icon, fw);
} else
{
c1 = QString::fromUtf8(container->getName().c_str());
c2 = tr("Type: ")+QString::fromUtf8(container->getTypeName().c_str());
loadIcon(parent_icon, container);
}
loadIcon(object_icon, o);
QStringList qsl;
qsl << QString::fromUtf8(o->getName().c_str()) << c1 << c2;
QTreeWidgetItem* item = new QTreeWidgetItem(qsl);
item->setIcon(1, QIcon(parent_icon));
item->setIcon(0, QIcon(object_icon));
item->setData(1, Qt::UserRole, qVariantFromValue((void*)container));
return item;
}

View File

@ -48,19 +48,35 @@ namespace libfwbuilder {
class FindWhereUsedWidget : public QWidget
{
Q_OBJECT
private:
private:
bool flShowObject;
libfwbuilder::FWObject* object;
std::set<libfwbuilder::FWObject *> resset;
std::map<QTreeWidgetItem*,libfwbuilder::FWObject *> mapping;
Ui::findWhereUsedWidget_q *m_widget;
void showObject(libfwbuilder::FWObject*);
public:
FindWhereUsedWidget(QWidget*p, const char * n = 0, Qt::WindowFlags f = 0, bool f_mini=false);
public:
FindWhereUsedWidget(QWidget*p, const char * n = 0,
Qt::WindowFlags f = 0, bool f_mini=false);
~FindWhereUsedWidget();
void setShowObject(bool fl);
/**
* Post-process set of FWObject* returned by
* FWObjectDatabase::findWhereObjectIsUsed to make it more
* suitable for the user. Since findWhereObjectIsUsed returns
* actual reference objects that point at the object we search
* for, humanizeSearchResults replaces them with appropriate
* parent objects. These can be either groups that hold
* references, or rules, which are two levels up.
*/
static void humanizeSearchResults(std::set<libfwbuilder::FWObject *>&);
static QTreeWidgetItem* createQTWidgetItem(libfwbuilder::FWObject* obj,
libfwbuilder::FWObject* container);
public slots:
virtual void hidePanel() {emit close();};

View File

@ -44,6 +44,7 @@
#include "newGroupDialog.h"
#include "FindObjectWidget.h"
#include "AskLibForCopyDialog.h"
#include "FindWhereUsedWidget.h"
#include <QTextEdit>
#include <QTime>
@ -395,7 +396,7 @@ void ObjectManipulator::showDeletedObjects(bool f)
if (dobj==NULL)
{
dobj=m_project->db()->create(Library::TYPENAME);
dobj = m_project->db()->create(Library::TYPENAME);
dobj->setId(FWObjectDatabase::DELETED_OBJECTS_ID);
dobj->setName("Deleted Objects");
dobj->setReadOnly(false);
@ -3190,7 +3191,8 @@ list<Firewall *> ObjectManipulator::findFirewallsForObject(FWObject *o)
FWObject *f=o;
while (f!=NULL && !Firewall::isA(f)) f=f->getParent();
if (f) fws.push_back(Firewall::cast(f));
m_project->db()->findWhereUsed(o,m_project->db(),resset);
m_project->db()->findWhereObjectIsUsed(o, m_project->db(), resset);
FindWhereUsedWidget::humanizeSearchResults(resset);
set<FWObject *>::iterator i=resset.begin();
for ( ;i!=resset.end();++i)

View File

@ -51,8 +51,6 @@ using namespace std;
void ProjectPanel::stateChanged(Qt::WindowStates oldState,
Qt::WindowStates newState)
{
if (fwbdebug) qDebug("ProjectPanel::stateChanged");
#if 0
// vk 09/16
bool is_maximized = ((newState & Qt::WindowMaximized) != 0);

View File

@ -1558,9 +1558,10 @@ void RuleSetView::paintEvent(QPaintEvent * event)
int last_visual_row = verticalHeader()->visualIndexAt(height());
if (last_visual_row >= 0)
{
#ifdef DEBUG_PAINT_CELL
if (fwbdebug) qDebug("RuleSetView::paintEvent: last_visual_row=%d",
last_visual_row);
#endif
QPainter painter(viewport());
for (int col=0; col < ncols; col++)
ruleDelegate->paint(&painter, QStyleOptionViewItem(),

View File

@ -5,14 +5,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>735</width>
<height>169</height>
<width>867</width>
<height>164</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>5</vsizetype>
<sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -24,9 +22,6 @@
<property name="margin" >
<number>6</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QGroupBox" name="dropBox" >
<property name="title" >
@ -36,15 +31,10 @@
<property name="margin" >
<number>6</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="FWObjectDropArea" native="1" name="dropArea" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -68,7 +58,7 @@
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>31</height>
@ -82,9 +72,7 @@
<item row="0" column="1" >
<widget class="QGroupBox" name="groupBox4" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>7</vsizetype>
<sizepolicy vsizetype="Expanding" hsizetype="MinimumExpanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -96,9 +84,6 @@
<property name="margin" >
<number>6</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QTreeWidget" name="resListView" >
<property name="allColumnsShowFocus" >
@ -106,7 +91,12 @@
</property>
<column>
<property name="text" >
<string>Parent Object</string>
<string>Object</string>
</property>
</column>
<column>
<property name="text" >
<string>Parent</string>
</property>
</column>
<column>
@ -117,6 +107,7 @@
</widget>
</item>
</layout>
<zorder>resListView</zorder>
</widget>
</item>
<item row="0" column="2" >
@ -131,9 +122,6 @@
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<spacer>
<property name="orientation" >
@ -142,7 +130,7 @@
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>20</height>

View File

@ -516,3 +516,14 @@ QString wordWrap(const QString& s, int maxchinline)
return res;
}
void loadIcon(QPixmap &pm, libfwbuilder::FWObject *obj)
{
QString icn_file = (":/Icons/" + obj->getTypeName()+"/icon-tree").c_str();
if ( ! QPixmapCache::find( icn_file, pm) )
{
pm.load( icn_file );
QPixmapCache::insert( icn_file, pm);
}
}

View File

@ -124,6 +124,8 @@ extern QString readHostOS(QComboBox *hostOS);
extern void setPlatform(QComboBox *platform,const QString &pl);
extern void setHostOS(QComboBox *hostOS,const QString &os);
extern void loadIcon(QPixmap &pm, libfwbuilder::FWObject *obj);
extern void setDisabledPalette(QWidget *w);
extern QString getAddrByName(const QString &name, int af_type);

View File

@ -93,14 +93,18 @@ void findByObjectType(FWObject *o,
}
}
FWReference* findRef(FWObject *o, FWObject *p)
/**
* Find reference to object <o> in the group <container> and return
* pointer to that reference object. If no such reference exists,
* return NULL.
*/
FWReference* findRef(FWObject *o, FWObject *container)
{
FWReference* ref=NULL;
FWObject::iterator i=p->begin();
for(;i!=p->end();++i)
FWObject::iterator i = container->begin();
for(; i!=container->end(); ++i)
{
ref=FWReference::cast(*i);
ref = FWReference::cast(*i);
if (ref!=NULL && ref->getPointer() == o)
{
break;