mirror of
https://github.com/fwbuilder/fwbuilder
synced 2025-10-16 07:28:25 +02:00
Added missing files (and modified .gitignore so it won't happen again).
This commit is contained in:
parent
12ad3fefcf
commit
73042fb3c7
1
.gitignore
vendored
1
.gitignore
vendored
@ -35,7 +35,6 @@ libtool
|
||||
.ui
|
||||
qtdbus_test
|
||||
fwbedit
|
||||
fwbuilder
|
||||
qrc_MainRes.cpp
|
||||
fwb_iosacl
|
||||
fwb_ipf
|
||||
|
172
src/libfwbuilder/src/fwbuilder/DynamicGroup.cpp
Normal file
172
src/libfwbuilder/src/fwbuilder/DynamicGroup.cpp
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2011 NetCitadel, LLC
|
||||
|
||||
Author: Theron Tock
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <fwbuilder/libfwbuilder-config.h>
|
||||
|
||||
#include <fwbuilder/DynamicGroup.h>
|
||||
#include <fwbuilder/XMLTools.h>
|
||||
#include <fwbuilder/FWObjectDatabase.h>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
#define TYPE_NONE "none"
|
||||
#define TYPE_ANY "any"
|
||||
#define KEYWORD_NONE ","
|
||||
#define KEYWORD_ANY ""
|
||||
|
||||
const char *DynamicGroup::TYPENAME={"DynamicGroup"};
|
||||
|
||||
DynamicGroup::DynamicGroup() : MultiAddress() {}
|
||||
|
||||
DynamicGroup::~DynamicGroup() {}
|
||||
|
||||
bool DynamicGroup::validateChild(FWObject *o)
|
||||
{
|
||||
if (FWObjectReference::cast(o)!=NULL) return true;
|
||||
|
||||
return FWObject::validateChild(o);
|
||||
}
|
||||
|
||||
void DynamicGroup::fromXML(xmlNodePtr root) throw(FWException)
|
||||
{
|
||||
FWObject::fromXML(root);
|
||||
|
||||
for (xmlNodePtr child = root->xmlChildrenNode;
|
||||
child != 0; child = child->next) {
|
||||
if (child->type != XML_ELEMENT_NODE) continue;
|
||||
assert(strcmp(FROMXMLCAST(child->name), "SelectionCriteria") == 0);
|
||||
|
||||
const char *type = FROMXMLCAST(xmlGetProp(child, TOXMLCAST("type")));
|
||||
const char *keyword =
|
||||
FROMXMLCAST(xmlGetProp(child, TOXMLCAST("keyword")));
|
||||
|
||||
string filter;
|
||||
if (makeFilter(filter, type, keyword)) {
|
||||
m_filter.push_back(filter);
|
||||
}
|
||||
|
||||
FREEXMLBUFF(type);
|
||||
FREEXMLBUFF(keyword);
|
||||
}
|
||||
}
|
||||
|
||||
xmlNodePtr DynamicGroup::toXML(xmlNodePtr parent) throw(FWException)
|
||||
{
|
||||
xmlNodePtr me = FWObject::toXML(parent, false);
|
||||
xmlRemoveProp(xmlHasProp(me, TOXMLCAST("run_time")));
|
||||
xmlNewProp(me, TOXMLCAST("name"), STRTOXMLCAST(getName()));
|
||||
xmlNewProp(me, TOXMLCAST("comment"), STRTOXMLCAST(getComment()));
|
||||
xmlNewProp(me, TOXMLCAST("ro"), TOXMLCAST(((getRO()) ? "True" : "False")));
|
||||
|
||||
list<string>::const_iterator iter;
|
||||
for (iter = m_filter.begin(); iter != m_filter.end(); ++iter) {
|
||||
string filter, type, keyword;
|
||||
if (!splitFilter(*iter, type, keyword)) continue;
|
||||
if (!makeFilter(filter, type, keyword)) continue;
|
||||
|
||||
xmlNodePtr item = xmlNewChild(me, NULL,
|
||||
TOXMLCAST("SelectionCriteria"), NULL);
|
||||
xmlNewProp(item, TOXMLCAST("type"), STRTOXMLCAST(type));
|
||||
xmlNewProp(item, TOXMLCAST("keyword"), STRTOXMLCAST(keyword));
|
||||
}
|
||||
|
||||
return me;
|
||||
}
|
||||
|
||||
bool DynamicGroup::splitFilter(const std::string &filter, std::string &type,
|
||||
std::string &keyword)
|
||||
{
|
||||
size_t pos = filter.find(',');
|
||||
if (pos == string::npos) return false;
|
||||
type = filter.substr(0, pos);
|
||||
keyword = filter.substr(pos + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DynamicGroup::makeFilter(string &filter, const string &type,
|
||||
const string &keyword)
|
||||
{
|
||||
if (type == TYPE_NONE || keyword == KEYWORD_NONE) return false;
|
||||
filter = type;
|
||||
filter.append(",");
|
||||
filter.append(keyword);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DynamicGroup::cmp(const FWObject *obj,
|
||||
bool recursive) throw(FWException)
|
||||
{
|
||||
if (!FWObject::cmp(obj, recursive)) return false;
|
||||
|
||||
const DynamicGroup *group = DynamicGroup::constcast(obj);
|
||||
return group->m_filter == m_filter;
|
||||
}
|
||||
|
||||
|
||||
FWObject& DynamicGroup::shallowDuplicate(const FWObject *other,
|
||||
bool preserve_id) throw (FWException)
|
||||
{
|
||||
const DynamicGroup *otherObj = DynamicGroup::constcast(other);
|
||||
m_filter = otherObj->m_filter;
|
||||
return FWObject::shallowDuplicate(otherObj, preserve_id);
|
||||
}
|
||||
|
||||
|
||||
bool DynamicGroup::isCompileTime() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void DynamicGroup::loadFromSource(bool ipv6, bool test_mode)
|
||||
throw (FWException)
|
||||
{
|
||||
FWObjectDatabase *root = getRoot();
|
||||
|
||||
FWObject::tree_iterator tree_iter;
|
||||
for (tree_iter = root->tree_begin();
|
||||
tree_iter != root->tree_end(); ++tree_iter) {
|
||||
FWObject *elem = (*tree_iter);
|
||||
if (elem == root) continue;
|
||||
|
||||
const set<string> &keywords = elem->getKeywords();
|
||||
|
||||
list<string>::const_iterator iter;
|
||||
for (iter = m_filter.begin(); iter != m_filter.end(); ++iter) {
|
||||
string type, keyword;
|
||||
splitFilter(*iter, type, keyword);
|
||||
|
||||
if ((type == TYPE_ANY || elem->getTypeName() == type) &&
|
||||
(keyword == KEYWORD_ANY || keywords.count(keyword) > 0)) {
|
||||
addRef(elem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
71
src/libfwbuilder/src/fwbuilder/DynamicGroup.h
Normal file
71
src/libfwbuilder/src/fwbuilder/DynamicGroup.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2011 NetCitadel, LLC
|
||||
|
||||
Author: Theron Tock
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __DynamicGroup_h__
|
||||
#define __DynamicGroup_h__
|
||||
|
||||
#include <fwbuilder/MultiAddress.h>
|
||||
|
||||
namespace libfwbuilder
|
||||
{
|
||||
|
||||
class DynamicGroup : public MultiAddress
|
||||
{
|
||||
std::list<std::string> m_filter;
|
||||
|
||||
public:
|
||||
DynamicGroup();
|
||||
virtual ~DynamicGroup();
|
||||
|
||||
DECLARE_FWOBJECT_SUBTYPE(DynamicGroup);
|
||||
DECLARE_DISPATCH_METHODS(DynamicGroup);
|
||||
|
||||
virtual void fromXML(xmlNodePtr parent) throw(FWException);
|
||||
virtual xmlNodePtr toXML(xmlNodePtr xml_parent_node) throw(FWException);
|
||||
|
||||
/* Each list entry is comma-separated list of matching criteria */
|
||||
const std::list<std::string> &getFilter() { return m_filter; }
|
||||
void setFilter(const std::list<std::string> &filter) { m_filter = filter; }
|
||||
|
||||
static bool splitFilter(const std::string &str, std::string &type,
|
||||
std::string &keyword);
|
||||
static bool makeFilter(std::string &filter, const std::string &type,
|
||||
const std::string &keyword);
|
||||
|
||||
bool cmp(const FWObject *obj, bool recursive=false) throw(FWException);
|
||||
FWObject& shallowDuplicate(const FWObject *other, bool preserve_id)
|
||||
throw (FWException);
|
||||
|
||||
virtual bool isCompileTime() const;
|
||||
virtual void loadFromSource(bool ipv6, bool test_mode=false)
|
||||
throw (FWException);
|
||||
|
||||
/*
|
||||
* verify whether given object type is approppriate as a child
|
||||
*/
|
||||
virtual bool validateChild(FWObject *o);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* __DynamicGroup_h__ */
|
Loading…
x
Reference in New Issue
Block a user