Indent every scope and put opening braces on the signature line

Namespace and extern "C" bodies are indented a level, so nesting is
visible from the indentation rather than only from the braces. Opening
braces stay on the line that opens the scope, including function
definitions, which previously carried theirs on a line of their own.
This commit is contained in:
2026-08-15 23:47:43 -04:00
parent 9fd7d2f433
commit 12a4f68025
13 changed files with 634 additions and 709 deletions

View File

@@ -63,16 +63,15 @@ struct dpm_ctx {
}; };
namespace dpm_core { namespace dpm_core {
/**
/**
* @brief Records a failure reason on the context * @brief Records a failure reason on the context
* *
* @param ctx The libdpm-core context; NULL is a no-op * @param ctx The libdpm-core context; NULL is a no-op
* @param msg The failure description * @param msg The failure description
*/ */
void set_error(dpm_ctx* ctx, const std::string& msg); void set_error(dpm_ctx* ctx, const std::string& msg);
/** /**
* @brief Loads all configuration files into the context * @brief Loads all configuration files into the context
* *
* Parses every .conf file in the context's configuration directory * Parses every .conf file in the context's configuration directory
@@ -80,6 +79,5 @@ void set_error(dpm_ctx* ctx, const std::string& msg);
* *
* @param ctx The libdpm-core context * @param ctx The libdpm-core context
*/ */
void load_config_dir(dpm_ctx* ctx); void load_config_dir(dpm_ctx* ctx);
} // namespace dpm_core } // namespace dpm_core

View File

@@ -65,8 +65,7 @@ struct dpm_cursor {
void dpm_internal_unload(void* handle); void dpm_internal_unload(void* handle);
namespace dpm_core { namespace dpm_core {
/**
/**
* @brief Runs the full load-time validation sequence against a module * @brief Runs the full load-time validation sequence against a module
* *
* Loads the named module's .so from the context's module path and * Loads the named module's .so from the context's module path and
@@ -77,8 +76,7 @@ namespace dpm_core {
* @param reason Receives the refusal reason on failure * @param reason Receives the refusal reason on failure
* @return The validated module (caller owns), or nullptr on failure * @return The validated module (caller owns), or nullptr on failure
*/ */
std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx, std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
const std::string& name, const std::string& name,
std::string& reason); std::string& reason);
} // namespace dpm_core } // namespace dpm_core

View File

@@ -23,14 +23,12 @@
#pragma once #pragma once
namespace dpm_core { namespace dpm_core {
/**
/**
* @brief Parses a strict X.Y.Z version string * @brief Parses a strict X.Y.Z version string
* *
* @param s The version string * @param s The version string
* @param out Receives the three parsed components * @param out Receives the three parsed components
* @return true on success; false on any malformation * @return true on success; false on any malformation
*/ */
bool parse_version(const char* s, long out[3]); bool parse_version(const char* s, long out[3]);
} // namespace dpm_core } // namespace dpm_core

View File

@@ -36,16 +36,14 @@
/** /**
* @brief Returns the module's own version * @brief Returns the module's own version
*/ */
extern "C" const char* dpm_module_version(void) extern "C" const char* dpm_module_version(void) {
{
return INFO_MODULE_VERSION; return INFO_MODULE_VERSION;
} }
/** /**
* @brief Returns the module's one-line description * @brief Returns the module's one-line description
*/ */
extern "C" const char* dpm_module_description(void) extern "C" const char* dpm_module_description(void) {
{
return "Reports and tests libdpm-core functionality."; return "Reports and tests libdpm-core functionality.";
} }
@@ -62,8 +60,7 @@ extern "C" const char* dpm_module_description(void)
* @return 0 on success, non-zero on failure * @return 0 on success, non-zero on failure
*/ */
extern "C" int dpm_module_execute(dpm_ctx* ctx, const char* command, extern "C" int dpm_module_execute(dpm_ctx* ctx, const char* command,
int argc, char** argv) int argc, char** argv) {
{
(void)argc; (void)argc;
(void)argv; (void)argv;

View File

@@ -33,18 +33,15 @@
#define INFO_VERSION "0.1.0" #define INFO_VERSION "0.1.0"
namespace { namespace {
std::string detect_architecture() {
std::string detect_architecture()
{
struct utsname system_info; struct utsname system_info;
if (uname(&system_info) == -1) { if (uname(&system_info) == -1) {
return "Unknown"; return "Unknown";
} }
return system_info.machine; return system_info.machine;
} }
std::string detect_os() std::string detect_os() {
{
struct utsname system_info; struct utsname system_info;
if (uname(&system_info) == -1) { if (uname(&system_info) == -1) {
return "Unknown"; return "Unknown";
@@ -92,12 +89,10 @@ std::string detect_os()
} }
return os; return os;
} }
} // namespace } // namespace
Command parse_command(const char* cmd_str) Command parse_command(const char* cmd_str) {
{
if (cmd_str == nullptr || std::strlen(cmd_str) == 0) { if (cmd_str == nullptr || std::strlen(cmd_str) == 0) {
return CMD_HELP; return CMD_HELP;
} }
@@ -116,8 +111,7 @@ Command parse_command(const char* cmd_str)
return CMD_UNKNOWN; return CMD_UNKNOWN;
} }
int cmd_help(dpm_ctx* ctx) int cmd_help(dpm_ctx* ctx) {
{
dpm_log(ctx, DPM_LOG_INFO, "DPM Info Module - Reports and tests libdpm-core functionality."); dpm_log(ctx, DPM_LOG_INFO, "DPM Info Module - Reports and tests libdpm-core functionality.");
dpm_log(ctx, DPM_LOG_INFO, ""); dpm_log(ctx, DPM_LOG_INFO, "");
dpm_log(ctx, DPM_LOG_INFO, "Available commands:"); dpm_log(ctx, DPM_LOG_INFO, "Available commands:");
@@ -130,8 +124,7 @@ int cmd_help(dpm_ctx* ctx)
return 0; return 0;
} }
int cmd_version(dpm_ctx* ctx) int cmd_version(dpm_ctx* ctx) {
{
std::string core_msg = "libdpm-core Version: "; std::string core_msg = "libdpm-core Version: ";
core_msg += dpm_core_version(); core_msg += dpm_core_version();
dpm_log(ctx, DPM_LOG_INFO, core_msg.c_str()); dpm_log(ctx, DPM_LOG_INFO, core_msg.c_str());
@@ -143,8 +136,7 @@ int cmd_version(dpm_ctx* ctx)
return 0; return 0;
} }
int cmd_system(dpm_ctx* ctx) int cmd_system(dpm_ctx* ctx) {
{
dpm_log(ctx, DPM_LOG_INFO, "System Information:"); dpm_log(ctx, DPM_LOG_INFO, "System Information:");
std::string os_msg = " OS: "; std::string os_msg = " OS: ";
@@ -158,8 +150,7 @@ int cmd_system(dpm_ctx* ctx)
return 0; return 0;
} }
int cmd_config(dpm_ctx* ctx) int cmd_config(dpm_ctx* ctx) {
{
dpm_log(ctx, DPM_LOG_INFO, "Configuration Information:"); dpm_log(ctx, DPM_LOG_INFO, "Configuration Information:");
const char* configured_path = dpm_config_get(ctx, "core", "modules", "path"); const char* configured_path = dpm_config_get(ctx, "core", "modules", "path");
@@ -175,8 +166,7 @@ int cmd_config(dpm_ctx* ctx)
return 0; return 0;
} }
int cmd_unknown(dpm_ctx* ctx, const char* command) int cmd_unknown(dpm_ctx* ctx, const char* command) {
{
std::string msg = "Unknown command: "; std::string msg = "Unknown command: ";
msg += (command ? command : ""); msg += (command ? command : "");
dpm_log(ctx, DPM_LOG_WARN, msg.c_str()); dpm_log(ctx, DPM_LOG_WARN, msg.c_str());

View File

@@ -33,12 +33,10 @@
#include <vector> #include <vector>
namespace { namespace {
/**
/**
* @brief Prints the CLI usage message * @brief Prints the CLI usage message
*/ */
void show_help() void show_help() {
{
std::printf( std::printf(
"Usage: dpm [options] [module] [module args...]\n" "Usage: dpm [options] [module] [module args...]\n"
"\n" "\n"
@@ -51,25 +49,24 @@ void show_help()
" -h, --help Show this help message\n" " -h, --help Show this help message\n"
"\n" "\n"
"For module-specific help, use: dpm <module> help\n"); "For module-specific help, use: dpm <module> help\n");
} }
/** /**
* @brief Parses a log level name * @brief Parses a log level name
* *
* @param name The level name (case-insensitive) * @param name The level name (case-insensitive)
* @return The DPM_LOG_* level, or -1 if unrecognized * @return The DPM_LOG_* level, or -1 if unrecognized
*/ */
int level_from_name(const char* name) int level_from_name(const char* name) {
{
if (strcasecmp(name, "FATAL") == 0) { return DPM_LOG_FATAL; } if (strcasecmp(name, "FATAL") == 0) { return DPM_LOG_FATAL; }
if (strcasecmp(name, "ERROR") == 0) { return DPM_LOG_ERROR; } if (strcasecmp(name, "ERROR") == 0) { return DPM_LOG_ERROR; }
if (strcasecmp(name, "WARN") == 0) { return DPM_LOG_WARN; } if (strcasecmp(name, "WARN") == 0) { return DPM_LOG_WARN; }
if (strcasecmp(name, "INFO") == 0) { return DPM_LOG_INFO; } if (strcasecmp(name, "INFO") == 0) { return DPM_LOG_INFO; }
if (strcasecmp(name, "DEBUG") == 0) { return DPM_LOG_DEBUG; } if (strcasecmp(name, "DEBUG") == 0) { return DPM_LOG_DEBUG; }
return -1; return -1;
} }
/** /**
* @brief Matches an argument against an option's short and long forms * @brief Matches an argument against an option's short and long forms
* *
* Recognizes the separate-value forms and the --option=value form. * Recognizes the separate-value forms and the --option=value form.
@@ -82,9 +79,8 @@ int level_from_name(const char* name)
* argument * argument
* @return true if the argument is this option * @return true if the argument is this option
*/ */
bool option_matches(const char* arg, const char* short_form, bool option_matches(const char* arg, const char* short_form,
const char* long_form, const char** inline_value) const char* long_form, const char** inline_value) {
{
if (std::strcmp(arg, short_form) == 0 || if (std::strcmp(arg, short_form) == 0 ||
std::strcmp(arg, long_form) == 0) { std::strcmp(arg, long_form) == 0) {
*inline_value = nullptr; *inline_value = nullptr;
@@ -98,16 +94,15 @@ bool option_matches(const char* arg, const char* short_form,
} }
return false; return false;
} }
/** /**
* @brief Prints the table of available modules * @brief Prints the table of available modules
* *
* @param ctx The libdpm-core context * @param ctx The libdpm-core context
* @return 0 on success, 1 on failure * @return 0 on success, 1 on failure
*/ */
int list_modules(dpm_ctx* ctx) int list_modules(dpm_ctx* ctx) {
{
dpm_cursor* cur = dpm_list_modules(ctx); dpm_cursor* cur = dpm_list_modules(ctx);
if (!cur) { if (!cur) {
const char* err = dpm_last_error(ctx); const char* err = dpm_last_error(ctx);
@@ -148,12 +143,10 @@ int list_modules(dpm_ctx* ctx)
std::printf("\nUse 'dpm <module> help' for module-specific help.\n"); std::printf("\nUse 'dpm <module> help' for module-specific help.\n");
return 0; return 0;
} }
} // namespace } // namespace
int main(int argc, char** argv) int main(int argc, char** argv) {
{
dpm_open_overrides overrides = {nullptr, nullptr, nullptr, -1}; dpm_open_overrides overrides = {nullptr, nullptr, nullptr, -1};
bool list = false; bool list = false;

View File

@@ -33,13 +33,11 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
namespace { namespace {
const char* DEFAULT_CONFIG_DIR = "/etc/dpm/conf.d/";
const char* DEFAULT_MODULE_PATH = "/usr/lib/dpm/modules/";
const char* DEFAULT_LOG_FILE = "/var/log/dpm/dpm.log";
const char* DEFAULT_CONFIG_DIR = "/etc/dpm/conf.d/"; std::string trim(const std::string& s) {
const char* DEFAULT_MODULE_PATH = "/usr/lib/dpm/modules/";
const char* DEFAULT_LOG_FILE = "/var/log/dpm/dpm.log";
std::string trim(const std::string& s)
{
const char* ws = " \t\r\n\f\v"; const char* ws = " \t\r\n\f\v";
size_t start = s.find_first_not_of(ws); size_t start = s.find_first_not_of(ws);
if (start == std::string::npos) { if (start == std::string::npos) {
@@ -47,18 +45,16 @@ std::string trim(const std::string& s)
} }
size_t end = s.find_last_not_of(ws); size_t end = s.find_last_not_of(ws);
return s.substr(start, end - start + 1); return s.substr(start, end - start + 1);
} }
std::string with_trailing_slash(std::string s) std::string with_trailing_slash(std::string s) {
{
if (!s.empty() && s.back() != '/') { if (!s.empty() && s.back() != '/') {
s += '/'; s += '/';
} }
return s; return s;
} }
bool parse_bool(const std::string& v, bool fallback) bool parse_bool(const std::string& v, bool fallback) {
{
std::string lower; std::string lower;
for (char c : v) { for (char c : v) {
lower += static_cast<char>(std::tolower(static_cast<unsigned char>(c))); lower += static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
@@ -70,20 +66,18 @@ bool parse_bool(const std::string& v, bool fallback)
return false; return false;
} }
return fallback; return fallback;
} }
int level_from_string(const std::string& v, int fallback) int level_from_string(const std::string& v, int fallback) {
{
if (v == "FATAL") { return DPM_LOG_FATAL; } if (v == "FATAL") { return DPM_LOG_FATAL; }
if (v == "ERROR") { return DPM_LOG_ERROR; } if (v == "ERROR") { return DPM_LOG_ERROR; }
if (v == "WARN") { return DPM_LOG_WARN; } if (v == "WARN") { return DPM_LOG_WARN; }
if (v == "INFO") { return DPM_LOG_INFO; } if (v == "INFO") { return DPM_LOG_INFO; }
if (v == "DEBUG") { return DPM_LOG_DEBUG; } if (v == "DEBUG") { return DPM_LOG_DEBUG; }
return fallback; return fallback;
} }
const char* level_name(int level) const char* level_name(int level) {
{
switch (level) { switch (level) {
case DPM_LOG_FATAL: return "FATAL"; case DPM_LOG_FATAL: return "FATAL";
case DPM_LOG_ERROR: return "ERROR"; case DPM_LOG_ERROR: return "ERROR";
@@ -92,11 +86,10 @@ const char* level_name(int level)
case DPM_LOG_DEBUG: return "DEBUG"; case DPM_LOG_DEBUG: return "DEBUG";
default: return "UNKNOWN"; default: return "UNKNOWN";
} }
} }
void parse_config_file(dpm_ctx* ctx, const fs::path& file, void parse_config_file(dpm_ctx* ctx, const fs::path& file,
const std::string& module_name) const std::string& module_name) {
{
std::ifstream in(file); std::ifstream in(file);
if (!in.is_open()) { if (!in.is_open()) {
return; return;
@@ -131,21 +124,17 @@ void parse_config_file(dpm_ctx* ctx, const fs::path& file,
ctx->config[module_name][section][key] = value; ctx->config[module_name][section][key] = value;
} }
} }
} // namespace } // namespace
namespace dpm_core { namespace dpm_core {
void set_error(dpm_ctx* ctx, const std::string& msg) {
void set_error(dpm_ctx* ctx, const std::string& msg)
{
if (ctx) { if (ctx) {
ctx->last_error = msg; ctx->last_error = msg;
} }
} }
void load_config_dir(dpm_ctx* ctx) void load_config_dir(dpm_ctx* ctx) {
{
std::error_code ec; std::error_code ec;
if (!fs::is_directory(ctx->config_dir, ec)) { if (!fs::is_directory(ctx->config_dir, ec)) {
return; return;
@@ -163,14 +152,11 @@ void load_config_dir(dpm_ctx* ctx)
} }
parse_config_file(ctx, entry.path(), entry.path().stem().string()); parse_config_file(ctx, entry.path(), entry.path().stem().string());
} }
} }
} // namespace dpm_core } // namespace dpm_core
extern "C" { extern "C" {
dpm_ctx* dpm_open(const dpm_open_overrides* overrides) {
dpm_ctx* dpm_open(const dpm_open_overrides* overrides)
{
/* Validate explicit overrides before allocating anything. */ /* Validate explicit overrides before allocating anything. */
if (overrides) { if (overrides) {
if (overrides->config_dir && *overrides->config_dir) { if (overrides->config_dir && *overrides->config_dir) {
@@ -231,10 +217,9 @@ dpm_ctx* dpm_open(const dpm_open_overrides* overrides)
} }
return ctx; return ctx;
} }
void dpm_close(dpm_ctx* ctx) void dpm_close(dpm_ctx* ctx) {
{
if (!ctx) { if (!ctx) {
return; return;
} }
@@ -246,11 +231,10 @@ void dpm_close(dpm_ctx* ctx)
} }
} }
delete ctx; delete ctx;
} }
const char* dpm_config_get(dpm_ctx* ctx, const char* module, const char* dpm_config_get(dpm_ctx* ctx, const char* module,
const char* section, const char* key) const char* section, const char* key) {
{
if (!ctx || !module || !section || !key) { if (!ctx || !module || !section || !key) {
return nullptr; return nullptr;
} }
@@ -271,10 +255,9 @@ const char* dpm_config_get(dpm_ctx* ctx, const char* module,
} }
return key_it->second.c_str(); return key_it->second.c_str();
} }
void dpm_log(dpm_ctx* ctx, int level, const char* message) void dpm_log(dpm_ctx* ctx, int level, const char* message) {
{
if (!ctx || !message) { if (!ctx || !message) {
return; return;
} }
@@ -306,22 +289,19 @@ void dpm_log(dpm_ctx* ctx, int level, const char* message)
ctx->write_to_log = false; ctx->write_to_log = false;
} }
} }
} }
const char* dpm_module_path(dpm_ctx* ctx) const char* dpm_module_path(dpm_ctx* ctx) {
{
if (!ctx) { if (!ctx) {
return nullptr; return nullptr;
} }
return ctx->module_path.c_str(); return ctx->module_path.c_str();
} }
const char* dpm_last_error(dpm_ctx* ctx) const char* dpm_last_error(dpm_ctx* ctx) {
{
if (!ctx || ctx->last_error.empty()) { if (!ctx || ctx->last_error.empty()) {
return nullptr; return nullptr;
} }
return ctx->last_error.c_str(); return ctx->last_error.c_str();
} }
} /* extern "C" */ } /* extern "C" */

View File

@@ -41,37 +41,31 @@ namespace fs = std::filesystem;
/* dlclose wrapper referenced from context.cpp so handle release stays /* dlclose wrapper referenced from context.cpp so handle release stays
in one translation unit with the loader. */ in one translation unit with the loader. */
void dpm_internal_unload(void* handle) void dpm_internal_unload(void* handle) {
{
if (handle) { if (handle) {
dlclose(handle); dlclose(handle);
} }
} }
namespace { namespace {
using execute_fn = int (*)(dpm_ctx*, const char*, int, char**);
using string_fn = const char* (*)(void);
using execute_fn = int (*)(dpm_ctx*, const char*, int, char**); /** dlsym with dlerror() discipline; returns nullptr on any error. */
using string_fn = const char* (*)(void); void* resolve(void* handle, const char* symbol) {
/** dlsym with dlerror() discipline; returns nullptr on any error. */
void* resolve(void* handle, const char* symbol)
{
dlerror(); dlerror();
void* addr = dlsym(handle, symbol); void* addr = dlsym(handle, symbol);
if (dlerror() != nullptr) { if (dlerror() != nullptr) {
return nullptr; return nullptr;
} }
return addr; return addr;
} }
} // namespace } // namespace
namespace dpm_core { namespace dpm_core {
std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
const std::string& name, const std::string& name,
std::string& reason) std::string& reason) {
{
std::string so_path = ctx->module_path + name + ".so"; std::string so_path = ctx->module_path + name + ".so";
std::error_code ec; std::error_code ec;
@@ -135,14 +129,11 @@ std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
mod->description = description; mod->description = description;
mod->execute = exec_f; mod->execute = exec_f;
return mod; return mod;
} }
} // namespace dpm_core } // namespace dpm_core
extern "C" { extern "C" {
dpm_module* dpm_require(dpm_ctx* ctx, const char* name) {
dpm_module* dpm_require(dpm_ctx* ctx, const char* name)
{
if (!ctx || !name || !*name) { if (!ctx || !name || !*name) {
return nullptr; return nullptr;
} }
@@ -163,10 +154,9 @@ dpm_module* dpm_require(dpm_ctx* ctx, const char* name)
dpm_module* mod = loaded.get(); dpm_module* mod = loaded.get();
ctx->modules[name] = std::move(loaded); ctx->modules[name] = std::move(loaded);
return mod; return mod;
} }
int dpm_module_info_of(dpm_ctx* ctx, dpm_module* mod, dpm_module_info* out) int dpm_module_info_of(dpm_ctx* ctx, dpm_module* mod, dpm_module_info* out) {
{
if (!ctx || !mod || !out) { if (!ctx || !mod || !out) {
return 1; return 1;
} }
@@ -175,19 +165,17 @@ int dpm_module_info_of(dpm_ctx* ctx, dpm_module* mod, dpm_module_info* out)
out->version = mod->version.c_str(); out->version = mod->version.c_str();
out->description = mod->description.c_str(); out->description = mod->description.c_str();
return 0; return 0;
} }
int dpm_execute(dpm_ctx* ctx, dpm_module* mod, const char* command, int dpm_execute(dpm_ctx* ctx, dpm_module* mod, const char* command,
int argc, char** argv) int argc, char** argv) {
{
if (!ctx || !mod || !mod->execute) { if (!ctx || !mod || !mod->execute) {
return 1; return 1;
} }
return mod->execute(ctx, command, argc, argv); return mod->execute(ctx, command, argc, argv);
} }
dpm_cursor* dpm_list_modules(dpm_ctx* ctx) dpm_cursor* dpm_list_modules(dpm_ctx* ctx) {
{
if (!ctx) { if (!ctx) {
return nullptr; return nullptr;
} }
@@ -245,21 +233,18 @@ dpm_cursor* dpm_list_modules(dpm_ctx* ctx)
} }
return cur; return cur;
} }
int dpm_cursor_next(dpm_cursor* cur, dpm_module_info* out) int dpm_cursor_next(dpm_cursor* cur, dpm_module_info* out) {
{
if (!cur || !out || cur->idx >= cur->infos.size()) { if (!cur || !out || cur->idx >= cur->infos.size()) {
return 1; return 1;
} }
*out = cur->infos[cur->idx]; *out = cur->infos[cur->idx];
cur->idx++; cur->idx++;
return 0; return 0;
} }
void dpm_cursor_free(dpm_cursor* cur) void dpm_cursor_free(dpm_cursor* cur) {
{
delete cur; delete cur;
} }
} /* extern "C" */ } /* extern "C" */

View File

@@ -30,15 +30,12 @@
/** libdpm-core.so's own version. */ /** libdpm-core.so's own version. */
#define DPM_CORE_VERSION_STR "1.0.0" #define DPM_CORE_VERSION_STR "1.0.0"
extern "C" const char* dpm_core_version(void) extern "C" const char* dpm_core_version(void) {
{
return DPM_CORE_VERSION_STR; return DPM_CORE_VERSION_STR;
} }
namespace dpm_core { namespace dpm_core {
bool parse_version(const char* s, long out[3]) {
bool parse_version(const char* s, long out[3])
{
if (!s || !*s) { if (!s || !*s) {
return false; return false;
} }
@@ -68,6 +65,5 @@ bool parse_version(const char* s, long out[3])
} }
return true; return true;
} }
} // namespace dpm_core } // namespace dpm_core

View File

@@ -20,19 +20,16 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
extern "C" const char* dpm_module_version(void) extern "C" const char* dpm_module_version(void) {
{
return "banana"; return "banana";
} }
extern "C" const char* dpm_module_description(void) extern "C" const char* dpm_module_description(void) {
{
return "Fixture with a malformed version."; return "Fixture with a malformed version.";
} }
extern "C" int dpm_module_execute(void* ctx, const char* command, extern "C" int dpm_module_execute(void* ctx, const char* command,
int argc, char** argv) int argc, char** argv) {
{
(void)ctx; (void)ctx;
(void)command; (void)command;
(void)argc; (void)argc;

View File

@@ -24,21 +24,18 @@
*/ */
#include <cstring> #include <cstring>
extern "C" const char* dpm_module_version(void) extern "C" const char* dpm_module_version(void) {
{
return "1.2.3"; return "1.2.3";
} }
extern "C" const char* dpm_module_description(void) extern "C" const char* dpm_module_description(void) {
{
return "Known-good stub module."; return "Known-good stub module.";
} }
/* Answers "ping" with 42 so a dispatch round trip is observable, and /* Answers "ping" with 42 so a dispatch round trip is observable, and
0 for anything else. */ 0 for anything else. */
extern "C" int dpm_module_execute(void* ctx, const char* command, extern "C" int dpm_module_execute(void* ctx, const char* command,
int argc, char** argv) int argc, char** argv) {
{
(void)ctx; (void)ctx;
(void)argc; (void)argc;
(void)argv; (void)argv;

View File

@@ -21,12 +21,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
extern "C" const char* dpm_module_version(void) extern "C" const char* dpm_module_version(void) {
{
return "1.0.0"; return "1.0.0";
} }
extern "C" const char* dpm_module_description(void) extern "C" const char* dpm_module_description(void) {
{
return "Fixture missing most of the contract."; return "Fixture missing most of the contract.";
} }

View File

@@ -50,14 +50,12 @@ static int g_checks = 0;
} \ } \
} while (0) } while (0)
static bool error_contains(dpm_ctx* ctx, const char* needle) static bool error_contains(dpm_ctx* ctx, const char* needle) {
{
const char* err = dpm_last_error(ctx); const char* err = dpm_last_error(ctx);
return err != nullptr && std::strstr(err, needle) != nullptr; return err != nullptr && std::strstr(err, needle) != nullptr;
} }
int main(void) int main(void) {
{
/* ---- dpm_open: invalid explicit override refuses ---- */ /* ---- dpm_open: invalid explicit override refuses ---- */
{ {
dpm_open_overrides bad = {"/does/not/exist/conf", nullptr, nullptr, -1}; dpm_open_overrides bad = {"/does/not/exist/conf", nullptr, nullptr, -1};