diff --git a/dpmdk/include/CommonModuleAPI.hpp b/dpmdk/include/CommonModuleAPI.hpp index d81ce4d..5385062 100644 --- a/dpmdk/include/CommonModuleAPI.hpp +++ b/dpmdk/include/CommonModuleAPI.hpp @@ -151,6 +151,16 @@ extern "C" { * @param level The log level (LOG_FATAL, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG) */ void dpm_set_logging_level(int level); + + /** + * @brief Gets the module path + * + * Returns the path where DPM modules are located, as determined by + * command-line arguments, configuration files, or defaults. + * + * @return The module path + */ + const char* dpm_get_module_path(void); } /** @@ -210,6 +220,11 @@ return env_value; /* Will be null if env var doesn't exist */ \ extern "C" void dpm_set_logging_level(int level) { \ std::cout << "[INFO] Verbosity level ignored, as all standalone executions have maximum verbosity" << std::endl; \ } \ +extern "C" const char* dpm_get_module_path(void) { \ +/* Get from environment variable or use default */ \ +const char* env_path = getenv("DPM_MODULE_PATH"); \ +return env_path ? env_path : "/usr/lib/dpm/modules/"; \ +} \ int main(int argc, char** argv) { \ /* Default to "help" if no command is provided */ \ const char* command = "help"; \ diff --git a/dpmdk/include/StandaloneModuleImpl.hpp b/dpmdk/include/StandaloneModuleImpl.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/ConfigManager.hpp b/include/ConfigManager.hpp index a9bbd2f..56d5e75 100644 --- a/include/ConfigManager.hpp +++ b/include/ConfigManager.hpp @@ -156,6 +156,12 @@ class ConfigManager { */ bool hasConfigKey(const char* section, const char* key) const; + // getter for _module_path + void setModulePath(const std::string& module_path); + + // setter for _module_path + std::string getModulePath() const; + private: /** * @brief Default section name to use when none is specified @@ -199,6 +205,8 @@ class ConfigManager { * @brief Configuration data structure: section -> key -> value */ std::map> _config_data; + + std::string _module_path; }; /** diff --git a/include/module_interface.hpp b/include/module_interface.hpp index 5c81c61..0131c1a 100644 --- a/include/module_interface.hpp +++ b/include/module_interface.hpp @@ -141,5 +141,16 @@ extern "C" { * @param level The log level as an integer (0=FATAL, 1=ERROR, 2=WARN, 3=INFO, 4=DEBUG) */ void dpm_set_logging_level(int level); + + /** + * @brief Gets the derived module path from the global configuration + * + * Allows modules to retrieve the configured module path used by DPM. + * This path is determined at runtime based on CLI arguments, configuration files, + * and defaults, in order of precedence. + * + * @return The module path as a string + */ + const char* dpm_get_module_path(void); } /** @} */ \ No newline at end of file diff --git a/modules/build/build.cpp b/modules/build/build.cpp index 4a2992c..8bf35a1 100644 --- a/modules/build/build.cpp +++ b/modules/build/build.cpp @@ -113,4 +113,5 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) { // If we're building in standalone mode, include the main function #ifdef BUILD_STANDALONE DPM_MODULE_STANDALONE_MAIN() -#endif // BUILD_STANDALONE \ No newline at end of file +#endif // BUILD_STANDALONE + diff --git a/modules/build/include/sealing.hpp b/modules/build/include/sealing.hpp index 0ce1a5e..9ea8aaa 100644 --- a/modules/build/include/sealing.hpp +++ b/modules/build/include/sealing.hpp @@ -37,7 +37,7 @@ * @param force Whether to force the operation even if warnings occur * @return 0 on success, non-zero on failure */ -int seal_stage_components( const std::string& stage_dir, bool force ); +extern "C" int seal_stage_components( const std::string& stage_dir, bool force ); /** * @brief Second phase of sealing to finalize a package @@ -50,7 +50,7 @@ int seal_stage_components( const std::string& stage_dir, bool force ); * @param force Whether to force the operation even if warnings occur * @return 0 on success, non-zero on failure */ -int seal_final_package(const std::string &stage_dir, const std::string &output_dir, bool force); +extern "C" int seal_final_package(const std::string &stage_dir, const std::string &output_dir, bool force); /** * @brief Unseals a package file back to stage format @@ -63,7 +63,7 @@ int seal_final_package(const std::string &stage_dir, const std::string &output_d * @param force Whether to force the operation even if warnings occur * @return 0 on success, non-zero on failure */ -int unseal_package(const std::string& package_path, const std::string& output_dir, bool force); +extern "C" int unseal_package(const std::string& package_path, const std::string& output_dir, bool force); /** * @brief Unseals component files in a stage directory @@ -74,4 +74,4 @@ int unseal_package(const std::string& package_path, const std::string& output_di * @param stage_dir Path to the stage directory containing components * @return 0 on success, non-zero on failure */ -int unseal_stage_components(const std::filesystem::path& stage_dir); \ No newline at end of file +extern "C" int unseal_stage_components(const std::filesystem::path& stage_dir); \ No newline at end of file diff --git a/modules/build/src/sealing.cpp b/modules/build/src/sealing.cpp index 2084dee..c2f0cca 100644 --- a/modules/build/src/sealing.cpp +++ b/modules/build/src/sealing.cpp @@ -432,7 +432,7 @@ bool smart_compress_component( const std::filesystem::path& stage_dir, const std } -int seal_stage_components(const std::string& stage_dir, bool force) +extern "C" int seal_stage_components(const std::string& stage_dir, bool force) { dpm_con(LOG_INFO, ("Sealing package stage: " + stage_dir).c_str()); @@ -487,7 +487,7 @@ int seal_stage_components(const std::string& stage_dir, bool force) return 0; } -int seal_final_package(const std::string &stage_dir, const std::string &output_dir, bool force) +extern "C" int seal_final_package(const std::string &stage_dir, const std::string &output_dir, bool force) { int stage_seal_result = seal_stage_components( stage_dir, force ); if ( stage_seal_result != 0 ) { @@ -525,7 +525,7 @@ int seal_final_package(const std::string &stage_dir, const std::string &output_d return 0; } -int unseal_package(const std::string& package_filepath, const std::string& output_dir, bool force) +extern "C" int unseal_package(const std::string& package_filepath, const std::string& output_dir, bool force) { dpm_log(LOG_INFO, ("Unsealing package: " + package_filepath).c_str()); @@ -657,7 +657,7 @@ bool smart_uncompress_component(const std::filesystem::path& stage_dir, const st return true; } -int unseal_stage_components(const std::filesystem::path& stage_dir) +extern "C" int unseal_stage_components(const std::filesystem::path& stage_dir) { dpm_log(LOG_INFO, ("Unsealing package components in: " + stage_dir.string()).c_str()); diff --git a/modules/verify/include/verify_commands.hpp b/modules/verify/include/verify_commands.hpp index 371bb64..2e25de5 100644 --- a/modules/verify/include/verify_commands.hpp +++ b/modules/verify/include/verify_commands.hpp @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include /** * @enum Command diff --git a/modules/verify/src/verify_commands.cpp b/modules/verify/src/verify_commands.cpp index a9c8282..23789c0 100644 --- a/modules/verify/src/verify_commands.cpp +++ b/modules/verify/src/verify_commands.cpp @@ -12,6 +12,39 @@ #include "verify_commands.hpp" +int check_and_load_build_module(void*& module_handle) { + // Get the module path using the new direct accessor + const char* module_path = dpm_get_module_path(); + if (!module_path || strlen(module_path) == 0) { + dpm_log(LOG_ERROR, "Module path not available"); + return 1; + } + + // Create a proper path object + std::filesystem::path modules_dir(module_path); + + // Build path to the build module + std::filesystem::path build_module_path = modules_dir / "build.so"; + + // Check if the file exists + if (!std::filesystem::exists(build_module_path)) { + dpm_log(LOG_ERROR, ("Build module not found at: " + build_module_path.string()).c_str()); + return 1; + } + + // Load the module + module_handle = dlopen(build_module_path.c_str(), RTLD_LAZY); + if (!module_handle) { + dpm_log(LOG_ERROR, ("Failed to load build module: " + std::string(dlerror())).c_str()); + return 1; + } + + // Clear any error + dlerror(); + + return 0; +} + int cmd_checksum(int argc, char** argv) { // Parse command line arguments bool all_packages = false; diff --git a/src/ConfigManager.cpp b/src/ConfigManager.cpp index b12f006..9dd6fc6 100644 --- a/src/ConfigManager.cpp +++ b/src/ConfigManager.cpp @@ -320,3 +320,11 @@ bool ConfigManager::getConfigBool(const char* section, const char* key, bool def // If not recognized, return default return defaultValue; } + +void ConfigManager::setModulePath(const std::string& module_path) { + _module_path = module_path; +} + +std::string ConfigManager::getModulePath() const { + return _module_path; +} \ No newline at end of file diff --git a/src/dpm.cpp b/src/dpm.cpp index a3225c4..9f3a1dd 100644 --- a/src/dpm.cpp +++ b/src/dpm.cpp @@ -129,6 +129,8 @@ int main( int argc, char* argv[] ) } } + g_config_manager.setModulePath(module_path); + // create a module loader object with the determined path ModuleLoader loader(module_path); diff --git a/src/module_interface.cpp b/src/module_interface.cpp index 3c8ce8a..cb06413 100644 --- a/src/module_interface.cpp +++ b/src/module_interface.cpp @@ -120,4 +120,10 @@ extern "C" void dpm_set_logging_level(int level) { } g_logger.setLogLevel(log_level); +} + +extern "C" const char* dpm_get_module_path(void) { + static std::string module_path; + module_path = g_config_manager.getModulePath(); + return module_path.c_str(); } \ No newline at end of file