error handling layer implemented, header boilerplated for licensing info
This commit is contained in:
@@ -1,32 +1,71 @@
|
||||
/**
|
||||
* @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
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "error.hpp"
|
||||
#include <filesystem>
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "module_interface.hpp"
|
||||
|
||||
|
||||
class ModuleLoader {
|
||||
public:
|
||||
// initializer
|
||||
explicit ModuleLoader(std::string module_path = "/usr/lib/dpm/modules/");
|
||||
DPMError list_available_modules(std::vector<std::string>& modules) const;
|
||||
DPMError get_module_path(std::string& path) const;
|
||||
public:
|
||||
// initializer
|
||||
explicit ModuleLoader(std::string module_path = "/usr/lib/dpm/modules/");
|
||||
DPMErrorCategory list_available_modules(std::vector<std::string>& modules) const;
|
||||
DPMErrorCategory get_module_path(std::string& path) const;
|
||||
|
||||
// Load and execute methods
|
||||
DPMError load_module(const std::string& module_name, void*& module_handle) const;
|
||||
DPMError execute_module(const std::string& module_name, const std::string& command) const;
|
||||
// Load and execute methods
|
||||
DPMErrorCategory load_module(const std::string& module_name, void*& module_handle) const;
|
||||
DPMErrorCategory execute_module(const std::string& module_name, const std::string& command) const;
|
||||
|
||||
// Get module version
|
||||
DPMError get_module_version(void* module_handle, std::string& version) const;
|
||||
// Get module version
|
||||
DPMErrorCategory get_module_version(void* module_handle, std::string& version) const;
|
||||
|
||||
// Get module description
|
||||
DPMError get_module_description(void* module_handle, std::string& description) const;
|
||||
// Get module description
|
||||
DPMErrorCategory get_module_description(void* module_handle, std::string& description) const;
|
||||
|
||||
// Check if all required symbols from module_interface.hpp are exported by the module
|
||||
DPMError validate_module_interface(void* module_handle, std::vector<std::string>& missing_symbols) const;
|
||||
// Check if all required symbols from module_interface.hpp are exported by the module
|
||||
DPMErrorCategory validate_module_interface(void* module_handle, std::vector<std::string>& missing_symbols) const;
|
||||
|
||||
private:
|
||||
std::string _module_path;
|
||||
// Helper method to check module path validity
|
||||
DPMErrorCategory check_module_path() const;
|
||||
|
||||
private:
|
||||
std::string _module_path;
|
||||
};
|
||||
@@ -1,12 +1,44 @@
|
||||
/**
|
||||
* @file dpm_interface.hpp
|
||||
* @brief Interface declarations for the DPM command-line functionality
|
||||
*
|
||||
* Defines the public interface methods that provide human-readable interaction
|
||||
* with the DPM core functionality, including module path validation and
|
||||
* module listing capabilities.
|
||||
*
|
||||
* @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 <iostream>
|
||||
#include <getopt.h>
|
||||
#include <vector>
|
||||
#include "error.hpp"
|
||||
#include <dlfcn.h>
|
||||
#include <iomanip>
|
||||
#include <filesystem>
|
||||
|
||||
#include "error.hpp"
|
||||
#include "ModuleLoader.hpp"
|
||||
#include "dpm_interface_helpers.hpp"
|
||||
|
||||
/*
|
||||
*
|
||||
@@ -21,16 +53,3 @@ int main_check_module_path(const ModuleLoader& loader);
|
||||
|
||||
// list the modules
|
||||
int main_list_modules(const ModuleLoader& loader);
|
||||
|
||||
// data structure for supplied arguments
|
||||
struct CommandArgs {
|
||||
std::string module_path;
|
||||
std::string module_name;
|
||||
std::string command; // All arguments combined into a single command string
|
||||
};
|
||||
|
||||
// parser for populating data structure for supplied arguments
|
||||
CommandArgs parse_args(int argc, char* argv[]);
|
||||
|
||||
// pairs DPMErrors to error messages, prints those error messages, and returns
|
||||
int print_error(DPMError error, const std::string& module_name, const std::string& module_path);
|
||||
44
include/dpm_interface_helpers.hpp
Normal file
44
include/dpm_interface_helpers.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file dpm_interface_helpers.hpp
|
||||
* @brief Helper functions for DPM command-line interface
|
||||
*
|
||||
* Provides utility functions for command-line argument parsing and
|
||||
* data structures for representing command arguments in a structured format.
|
||||
* These helpers are used by the main DPM interface to process user input.
|
||||
*
|
||||
* @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 <iostream>
|
||||
#include <getopt.h>
|
||||
|
||||
// data structure for supplied arguments
|
||||
struct CommandArgs {
|
||||
std::string module_path;
|
||||
std::string module_name;
|
||||
std::string command; // All arguments combined into a single command string
|
||||
};
|
||||
|
||||
// parse dpm cli arguments into a serialized structure
|
||||
CommandArgs parse_args( int argc, char * argv[] );
|
||||
@@ -1,10 +1,42 @@
|
||||
/**
|
||||
* @file error.hpp
|
||||
* @brief Error handling system for the DPM utility
|
||||
*
|
||||
* Defines the error categories, error context structure, and utility
|
||||
* functions for error handling throughout the DPM system. Provides a
|
||||
* consistent approach to error reporting and management.
|
||||
*
|
||||
* @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 <iostream>
|
||||
|
||||
// global errors for the core DPM routing/execution component
|
||||
enum class DPMError {
|
||||
enum class DPMErrorCategory {
|
||||
SUCCESS,
|
||||
PATH_NOT_FOUND,
|
||||
PATH_NOT_DIRECTORY,
|
||||
PATH_TOO_LONG,
|
||||
PERMISSION_DENIED,
|
||||
MODULE_NOT_FOUND,
|
||||
MODULE_NOT_LOADED,
|
||||
@@ -13,4 +45,18 @@ enum class DPMError {
|
||||
SYMBOL_NOT_FOUND,
|
||||
SYMBOL_EXECUTION_FAILED,
|
||||
UNDEFINED_ERROR
|
||||
};
|
||||
};
|
||||
|
||||
// A generic context object that can hold any error-specific data
|
||||
// only DPMErrorCategory is required, all other fields are optional
|
||||
typedef struct {
|
||||
DPMErrorCategory error;
|
||||
const char * module_name;
|
||||
const char * module_path;
|
||||
const char * message;
|
||||
// Add other potential fields as needed as all fields beyond error are optional
|
||||
} FlexDPMError;
|
||||
|
||||
// shorthand for creating a FlexDPMError instance
|
||||
FlexDPMError make_error( DPMErrorCategory error_category );
|
||||
|
||||
|
||||
53
include/handlers.hpp
Normal file
53
include/handlers.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @file handlers.hpp
|
||||
* @brief Error handling functions for the DPM system
|
||||
*
|
||||
* Defines specialized handler functions for each error category in the DPM
|
||||
* error system. These handlers translate error codes into user-friendly
|
||||
* messages and provide appropriate exit behavior for different error conditions.
|
||||
*
|
||||
* @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 <iostream>
|
||||
|
||||
#include "error.hpp"
|
||||
|
||||
// fatal error routing method
|
||||
int handle_error(FlexDPMError context);
|
||||
|
||||
// declare a required field
|
||||
void validate_field(FlexDPMError context, const char* field_name, const void* field_value);
|
||||
|
||||
// Individual error handler prototypes
|
||||
int handle_path_not_found(FlexDPMError context);
|
||||
int handle_path_not_directory(FlexDPMError context);
|
||||
int handle_path_too_long(FlexDPMError context);
|
||||
int handle_permission_denied(FlexDPMError context);
|
||||
int handle_module_not_found(FlexDPMError context);
|
||||
int handle_module_not_loaded(FlexDPMError context);
|
||||
int handle_module_load_failed(FlexDPMError context);
|
||||
int handle_invalid_module(FlexDPMError context);
|
||||
int handle_symbol_not_found(FlexDPMError context);
|
||||
int handle_symbol_execution_failed(FlexDPMError context);
|
||||
int handle_undefined_error(FlexDPMError context);
|
||||
@@ -1,3 +1,33 @@
|
||||
/**
|
||||
* @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>
|
||||
|
||||
Reference in New Issue
Block a user