see #1548 working on deduplication of network objects

This commit is contained in:
Vadim Kurland
2011-03-23 22:16:18 -07:00
parent 97061f54f0
commit 909470a0bf
8 changed files with 67 additions and 39 deletions
+57 -31
View File
@@ -36,6 +36,9 @@
#include <string>
#include <QtDebug>
extern int fwbdebug;
using namespace libfwbuilder;
@@ -46,10 +49,10 @@ AddressObjectMaker::~AddressObjectMaker() {}
FWObject* AddressObjectMaker::createObject(ObjectSignature &sig)
{
assert( ! sig.type_name.isEmpty());
// FWObject *obj = findMatchingObject(sig);
// if (obj) return obj;
FWObject *obj = findMatchingObject(sig);
if (obj) return obj;
FWObject *obj = NULL;
if (sig.type_name == AddressRange::TYPENAME)
obj = createAddressRange(sig.address_range_start, sig.address_range_end);
@@ -77,11 +80,49 @@ FWObject* AddressObjectMaker::createAddress(const QString &addr,
correct_nm = (~orig_nm).toString().c_str();
}
try
{
InetAddr(correct_nm.toStdString());
} catch (FWException &ex)
{
if (correct_nm.contains('.'))
{
// netmask has '.' in it but conversion failed.
throw ObjectMakerException(
QString("Error converting netmask '%1'").arg(correct_nm));
} else
{
// no dot in netmask, perhaps it is specified by its length?
// if netmask is specified by length, need to use special
// constructor for class Netmask to convert
bool ok = false;
int nm_len = correct_nm.toInt(&ok);
if (ok)
{
correct_nm = InetAddr(nm_len).toString().c_str();
} else
{
// could not convert netmask as simple integer
throw ObjectMakerException(
QString("Error converting netmask '%1'").arg(correct_nm));
}
}
}
ObjectSignature sig;
sig.address = addr;
sig.netmask = correct_nm;
if ( correct_nm == InetAddr::getAllOnes().toString().c_str() )
{
QString name;
try
{
sig.type_name = IPv4::TYPENAME;
FWObject *obj = findMatchingObject(sig);
if (obj) return obj;
InetAddr obj_addr(addr.toStdString()); // testing if string converts to an address
name = QString("h-") + addr;
Address *a = Address::cast(
@@ -89,12 +130,17 @@ FWObject* AddressObjectMaker::createAddress(const QString &addr,
a->setAddress(obj_addr);
a->setNetmask(InetAddr(InetAddr::getAllOnes()));
return a;
} catch(FWException &ex)
{
// address text line can not be converted to ipv4 address.
// Since parsers do not understand ipv6 yet, assume this
// is a host address and create DNSName object
sig.type_name = DNSName::TYPENAME;
FWObject *obj = findMatchingObject(sig);
if (obj) return obj;
name = addr;
DNSName *da = DNSName::cast(
ObjectMaker::createObject(DNSName::TYPENAME, name.toStdString()));
@@ -105,6 +151,12 @@ FWObject* AddressObjectMaker::createAddress(const QString &addr,
} else
{
sig.type_name = Network::TYPENAME;
qDebug() << "Search for " << sig.toString();
FWObject *obj = findMatchingObject(sig);
if (obj) return obj;
QString name = QString("net-") + addr + "/" + correct_nm;
Network *net = Network::cast(
@@ -118,34 +170,8 @@ FWObject* AddressObjectMaker::createAddress(const QString &addr,
QString("Error converting address '%1'").arg(addr));
}
try
{
net->setNetmask( InetAddr(correct_nm.toStdString()) );
} catch (FWException &ex)
{
if (correct_nm.contains('.'))
{
// netmask has '.' in it but conversion failed.
throw ObjectMakerException(
QString("Error converting netmask '%1'").arg(correct_nm));
} else
{
// no dot in netmask, perhaps it is specified by its length?
// if netmask is specified by length, need to use special
// constructor for class Netmask to convert
bool ok = false;
int nm_len = correct_nm.toInt(&ok);
if (ok)
{
net->setNetmask( InetAddr(nm_len) );
} else
{
// could not convert netmask as simple integer
throw ObjectMakerException(
QString("Error converting netmask '%1'").arg(correct_nm));
}
}
}
// we have already verified netmask above
net->setNetmask( InetAddr(correct_nm.toStdString()) );
return net;
}
+4 -2
View File
@@ -838,12 +838,14 @@ void ObjectMaker::prepareForDeduplication(FWObject *root)
root->dispatch(&sig, (void*)(NULL));
qDebug() << "Registering " << sig.toString();
registerNamedObject(sig, root);
registerAnonymousObject(sig, root); // this erases sig.object_name
}
if (Library::isA(root) && root->getId() == FWObjectDatabase::DELETED_OBJECTS_ID)
return;
if (Library::isA(root) &&
root->getId() == FWObjectDatabase::DELETED_OBJECTS_ID) return;
for (FWObject::iterator it=root->begin(); it!=root->end(); ++it)
{
+1 -1
View File
@@ -1,4 +1,4 @@
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgLexer.cpp"$ */
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgLexer.cpp"$ */
#line 42 "pix.g"
// gets inserted before the antlr generated includes in the cpp
+1 -1
View File
@@ -9,7 +9,7 @@
#line 11 "PIXCfgLexer.hpp"
#include <antlr/config.hpp>
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgLexer.hpp"$ */
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgLexer.hpp"$ */
#include <antlr/CommonToken.hpp>
#include <antlr/InputBuffer.hpp>
#include <antlr/BitSet.hpp>
+1 -1
View File
@@ -1,4 +1,4 @@
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgParser.cpp"$ */
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgParser.cpp"$ */
#line 42 "pix.g"
// gets inserted before the antlr generated includes in the cpp
+1 -1
View File
@@ -9,7 +9,7 @@
#line 11 "PIXCfgParser.hpp"
#include <antlr/config.hpp>
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgParser.hpp"$ */
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgParser.hpp"$ */
#include <antlr/TokenStream.hpp>
#include <antlr/TokenBuffer.hpp>
#include "PIXCfgParserTokenTypes.hpp"
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef INC_PIXCfgParserTokenTypes_hpp_
#define INC_PIXCfgParserTokenTypes_hpp_
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgParserTokenTypes.hpp"$ */
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgParserTokenTypes.hpp"$ */
#ifndef CUSTOM_API
# define CUSTOM_API
+1 -1
View File
@@ -1,4 +1,4 @@
// $ANTLR 2.7.7 (20090306): pix.g -> PIXCfgParserTokenTypes.txt$
// $ANTLR 2.7.7 (20100319): pix.g -> PIXCfgParserTokenTypes.txt$
PIXCfgParser // output token vocab name
NEWLINE=4
QUIT="quit"=5