modules now can access config entries in a new conf.d dir pulled by DPM core (ini file format)
This commit is contained in:
88
include/ConfigManager.hpp
Normal file
88
include/ConfigManager.hpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* @file ConfigManager.hpp
|
||||
* @brief Configuration management system for the DPM utility
|
||||
*
|
||||
* Defines the ConfigManager class which is responsible for loading, parsing,
|
||||
* and providing access to configuration values from INI-style files in the
|
||||
* /etc/dpm/conf.d/ directory. Supports the configuration needs of both the
|
||||
* DPM core and its modules.
|
||||
*
|
||||
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
||||
* @author Chris Punches <chris.punches@silogroup.org>
|
||||
*
|
||||
* Part of the Dark Horse Linux Package Manager (DPM)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For bug reports or contributions, please contact the dhlp-contributors
|
||||
* mailing list at: https://lists.darkhorselinux.org/mailman/listinfo/dhlp-contributors
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <optional>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
|
||||
class ConfigManager {
|
||||
public:
|
||||
// Constructor
|
||||
ConfigManager(const std::string& config_dir = "/etc/dpm/conf.d/");
|
||||
|
||||
// Load all configuration files from the config directory
|
||||
bool loadConfigurations();
|
||||
|
||||
// Get configuration values with type conversion
|
||||
const char* getConfigValue(const char* section, const char* key) const;
|
||||
std::string getConfigString(const char* section, const char* key, const std::string& defaultValue = "") const;
|
||||
int getConfigInt(const char* section, const char* key, int defaultValue = 0) const;
|
||||
double getConfigDouble(const char* section, const char* key, double defaultValue = 0.0) const;
|
||||
bool getConfigBool(const char* section, const char* key, bool defaultValue = false) const;
|
||||
|
||||
// Check if configuration directory exists
|
||||
bool configDirExists() const;
|
||||
|
||||
// Check if a configuration key exists
|
||||
bool hasConfigKey(const char* section, const char* key) const;
|
||||
|
||||
private:
|
||||
// Default section name to use when none is specified
|
||||
static constexpr const char* DEFAULT_SECTION = "MAIN";
|
||||
|
||||
// Parse a single configuration file
|
||||
bool parseConfigFile(const std::filesystem::path& config_file);
|
||||
|
||||
// Trim whitespace from a string
|
||||
std::string trimWhitespace(const std::string& str) const;
|
||||
|
||||
// Find a key in the given section or in the default section
|
||||
std::optional<std::reference_wrapper<const std::string>> findConfigValue(const std::string& section, const std::string& key) const;
|
||||
|
||||
// Configuration directory path
|
||||
std::string _config_dir;
|
||||
|
||||
// Configuration data structure: section -> key -> value
|
||||
std::map<std::string, std::map<std::string, std::string>> _config_data;
|
||||
};
|
||||
|
||||
// Global configuration manager instance
|
||||
extern ConfigManager g_config_manager;
|
||||
@@ -1,31 +1,31 @@
|
||||
/**
|
||||
* @file ModuleLoader.hpp
|
||||
* @brief Dynamic module loading and management for DPM
|
||||
*
|
||||
* Defines the ModuleLoader class which is responsible for finding, loading,
|
||||
* validating, and executing DPM modules. It handles the dynamic loading of
|
||||
* shared objects and ensures they conform to the expected module interface.
|
||||
*
|
||||
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
||||
* @author Chris Punches <chris.punches@silogroup.org>
|
||||
*
|
||||
* Part of the Dark Horse Linux Package Manager (DPM)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For bug reports or contributions, please contact the dhlp-contributors
|
||||
* mailing list at: https://lists.darkhorselinux.org/mailman/listinfo/dhlp-contributors
|
||||
* @file ModuleLoader.hpp
|
||||
* @brief Dynamic module loading and management for DPM
|
||||
*
|
||||
* Defines the ModuleLoader class which is responsible for finding, loading,
|
||||
* validating, and executing DPM modules. It handles the dynamic loading of
|
||||
* shared objects and ensures they conform to the expected module interface.
|
||||
*
|
||||
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
||||
* @author Chris Punches <chris.punches@silogroup.org>
|
||||
*
|
||||
* Part of the Dark Horse Linux Package Manager (DPM)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For bug reports or contributions, please contact the dhlp-contributors
|
||||
* mailing list at: https://lists.darkhorselinux.org/mailman/listinfo/dhlp-contributors
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -33,16 +33,15 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <dlfcn.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "module_interface.hpp"
|
||||
|
||||
|
||||
class ModuleLoader {
|
||||
public:
|
||||
// initializer
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file dpm_interface.hpp
|
||||
* @file dpm_interface.hpp
|
||||
* @brief Interface declarations for the DPM command-line functionality
|
||||
*
|
||||
* Defines the public interface methods that provide human-readable interaction
|
||||
@@ -30,11 +30,11 @@
|
||||
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
#include <vector>
|
||||
#include <dlfcn.h>
|
||||
#include <iomanip>
|
||||
#include <filesystem>
|
||||
#include <dlfcn.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "ModuleLoader.hpp"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file dpm_interface_helpers.hpp
|
||||
* @file dpm_interface_helpers.hpp
|
||||
* @brief Helper functions for DPM command-line interface
|
||||
*
|
||||
* Provides utility functions for command-line argument parsing and
|
||||
@@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file error.hpp
|
||||
* @file error.hpp
|
||||
* @brief Error handling system for the DPM utility
|
||||
*
|
||||
* Defines the error categories, error context structure, and utility
|
||||
@@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// global errors for the core DPM routing/execution component
|
||||
@@ -59,4 +60,3 @@ typedef struct {
|
||||
|
||||
// shorthand for creating a FlexDPMError instance
|
||||
FlexDPMError make_error( DPMErrorCategory error_category );
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file handlers.hpp
|
||||
* @file handlers.hpp
|
||||
* @brief Error handling functions for the DPM system
|
||||
*
|
||||
* Defines specialized handler functions for each error category in the DPM
|
||||
@@ -29,8 +29,8 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
|
||||
#include <iostream>
|
||||
#include "error.hpp"
|
||||
|
||||
// fatal error routing method
|
||||
|
||||
@@ -1,36 +1,41 @@
|
||||
/**
|
||||
* @file module_interface.hpp
|
||||
* @brief Defines the interface for DPM modules
|
||||
*
|
||||
* Establishes the required symbols and common interface that all DPM modules
|
||||
* must implement to be loadable and executable by the core DPM system.
|
||||
* This forms the contract between the main DPM application and its modules.
|
||||
*
|
||||
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
||||
* @author Chris Punches <chris.punches@silogroup.org>
|
||||
*
|
||||
* Part of the Dark Horse Linux Package Manager (DPM)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For bug reports or contributions, please contact the dhlp-contributors
|
||||
* mailing list at: https://lists.darkhorselinux.org/mailman/listinfo/dhlp-contributors
|
||||
* @file module_interface.hpp
|
||||
* @brief Defines the interface for DPM modules
|
||||
*
|
||||
* Establishes the required symbols and common interface that all DPM modules
|
||||
* must implement to be loadable and executable by the core DPM system.
|
||||
* This forms the contract between the main DPM application and its modules.
|
||||
*
|
||||
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
||||
* @author Chris Punches <chris.punches@silogroup.org>
|
||||
*
|
||||
* Part of the Dark Horse Linux Package Manager (DPM)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For bug reports or contributions, please contact the dhlp-contributors
|
||||
* mailing list at: https://lists.darkhorselinux.org/mailman/listinfo/dhlp-contributors
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include "ConfigManager.hpp"
|
||||
|
||||
|
||||
/*
|
||||
* Provides reserved symbol names we look for in modules.
|
||||
@@ -59,4 +64,7 @@ extern "C" {
|
||||
|
||||
// Callback function exposed by DPM core for modules to use
|
||||
int dpm_core_callback(const char* action, const char* data);
|
||||
}
|
||||
|
||||
// Direct configuration access function
|
||||
const char* dpm_get_config(const char* section, const char* key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user