Skip to content

Commit

Permalink
added plugin read config op
Browse files Browse the repository at this point in the history
  • Loading branch information
dulive committed Feb 1, 2022
1 parent d2907b1 commit 78b72c5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/mptcpd/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ MPTCPD_API bool mptcpd_plugin_register_ops(
char const *name,
struct mptcpd_plugin_ops const *ops);

MPTCPD_API bool mptcpd_plugin_read_config(char const *filename,
mptcpd_parse_func_t fun,
void *user_data);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions include/mptcpd/private/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct mptcpd_interface;
*/
MPTCPD_API bool mptcpd_plugin_load(char const *dir,
char const *default_name,
char const *plugins_conf_dir,
struct l_queue const *plugins_to_load,
struct mptcpd_pm *pm);

Expand Down
31 changes: 31 additions & 0 deletions lib/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# define MPTCP_PM_NAME_LEN GENL_NAMSIZ
#endif

#include <mptcpd/private/configuration.h>
#include <mptcpd/private/plugin.h>
#include <mptcpd/plugin.h>

Expand Down Expand Up @@ -86,6 +87,8 @@ static char _default_name[MPTCP_PM_NAME_LEN + 1];
*/
static struct mptcpd_plugin_ops const *_default_ops;

static char *_conf_dir;

// ----------------------------------------------------------------
// Implementation Details
// ----------------------------------------------------------------
Expand Down Expand Up @@ -432,6 +435,7 @@ static void unload_plugins(struct mptcpd_pm *pm)

bool mptcpd_plugin_load(char const *dir,
char const *default_name,
char const *plugins_conf_dir,
struct l_queue const *plugins_to_load,
struct mptcpd_pm *pm)
{
Expand All @@ -440,6 +444,14 @@ bool mptcpd_plugin_load(char const *dir,
return false;
}

if (plugins_conf_dir == NULL) {
l_error("No plugins configuration directory specified.");
return false;
}

if (_conf_dir == NULL)
_conf_dir = l_strdup(plugins_conf_dir);

if (_plugin_infos == NULL)
_plugin_infos = l_queue_new();

Expand Down Expand Up @@ -569,6 +581,25 @@ bool mptcpd_plugin_register_ops(char const *name,
return registered;
}

bool mptcpd_plugin_read_config(char const *filename,
mptcpd_parse_func_t fun,
void *user_data)
{
assert(filename != NULL);
assert(fun != NULL);

char *const path = l_strdup_printf("%s/%s.conf",
_conf_dir,
filename);

bool success = mptcpd_config_read(path, fun, user_data);

l_free(path);

return success;
}


// ----------------------------------------------------------------
// Plugin Operation Callback Invocation
// ----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/path_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ static void complete_pm_init(void *data)
*/
if (!mptcpd_plugin_load(pm->config->plugin_dir,
pm->config->default_plugin,
pm->config->plugins_conf_dir,
pm->config->plugins_to_load,
pm)) {
l_error("Unable to load path manager plugins.");
Expand Down

0 comments on commit 78b72c5

Please sign in to comment.