[firewalld-recode] master: Added initial implementation of the loadConfig method (90b853d)
by mildew@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/firewalld-recode.git
On branch : master
>---------------------------------------------------------------
commit 90b853d6b30ecc35d4b85d2732fbd43614ae5d98
Author: Daniel Kopecek <dkopecek(a)redhat.com>
Date: Mon Jul 28 18:09:29 2014 +0200
Added initial implementation of the loadConfig method
>---------------------------------------------------------------
firewalld.cpp | 37 +++++++++++++++++++++++++++++++++++--
firewalld.hpp | 32 ++++++++++++++++++++++++++++++--
2 files changed, 65 insertions(+), 4 deletions(-)
diff --git a/firewalld.cpp b/firewalld.cpp
index d2d4efb..6beade7 100644
--- a/firewalld.cpp
+++ b/firewalld.cpp
@@ -88,6 +88,13 @@ namespace firewalld
_glib_loop->quit();
}
+ void FirewallD::loadConfig()
+ {
+ LOG(TRACE) << "Loading configuration";
+ loadServiceDefinitions("./config/services/");
+ loadZoneDefinitions("./config/zones/");
+ }
+
void FirewallD::setPanicMode(bool panic_mode)
{
// Set the panic mode
@@ -117,12 +124,38 @@ namespace firewalld
}
}
- void FirewallD::loadServiceDefinitions()
+ void FirewallD::loadServiceDefinitions(const String& directory)
{
+ LOG(TRACE) << "Loading Service definitions from " << directory;
+ loadFiles(directory, std::regex(".*\\.xml"/*"[a-zA-Z0-9]+\\.xml"*/),
+ &FirewallD::loadServiceDefinition, this);
+ return;
}
- void FirewallD::loadZoneDefinitions()
+ void FirewallD::loadZoneDefinitions(const String& directory)
{
+ LOG(TRACE) << "Loading Zone definitions from " << directory;
+ loadFiles(directory, std::regex(".*\\.xml"/*"[a-zA-Z0-9]+\\.xml"*/),
+ &FirewallD::loadZoneDefinition, this);
+ return;
+ }
+
+ void FirewallD::loadServiceDefinition(const String& filepath)
+ {
+ LOG(TRACE) << "Loading Service definition from " << filepath;
+ Service* service = new Service();
+ service->initFromXML(filepath);
+ _defined_services[service->identifier()] = service;
+ return;
+ }
+
+ void FirewallD::loadZoneDefinition(const String& filepath)
+ {
+ LOG(TRACE) << "Loading Zone definition from " << filepath;
+ Zone* zone = new Zone();
+ zone->initFromXML(filepath);
+ _defined_zones[zone->identifier()] = zone;
+ return;
}
void FirewallD::dbus_method_handle(const ustring& name, const DBusParameters& parameters, DBusResultBuilder& result)
diff --git a/firewalld.hpp b/firewalld.hpp
index fdd4ad9..58f42c0 100644
--- a/firewalld.hpp
+++ b/firewalld.hpp
@@ -37,6 +37,7 @@ namespace firewalld
FirewallD();
void run();
void quit();
+ void loadConfig();
bool panicMode() const { return _panic_mode; }
void setPanicMode(bool panic_mode);
@@ -49,8 +50,35 @@ namespace firewalld
static const FirewallD* instance();
protected:
- void loadServiceDefinitions();
- void loadZoneDefinitions();
+ /**
+ * Load Service object definitions from a directory.
+ * This functions looks for .xml files with service definitions
+ * inside the given directory. Only files with .xml extension
+ * are processed. Subdirectories aren't descended into.
+ */
+ void loadServiceDefinitions(const String& directory);
+
+ /**
+ * Load Zone object definitions from a directory.
+ * This functions looks for .xml files with zone definitions
+ * inside the given directory. Only files with .xml extension
+ * are processed. Subdirectories aren't descended into.
+ */
+ void loadZoneDefinitions(const String& directory);
+
+ /**
+ * Load a Service object from a file.
+ * This function read the contents of the given file
+ * and tries to parse it as a service definition.
+ */
+ void loadServiceDefinition(const String& filepath);
+
+ /**
+ * Load a Zone object from a file.
+ * This function read the contents of the given file
+ * and tries to parse it as a zone definition.
+ */
+ void loadZoneDefinition(const String& filepath);
void dbus_method_handle(const UString& name,
const DBusParameters& parameters,