Skip to content

Commit 78b72c5

Browse files
author
João Meira
committed
added plugin read config op
1 parent d2907b1 commit 78b72c5

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

include/mptcpd/plugin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ MPTCPD_API bool mptcpd_plugin_register_ops(
345345
char const *name,
346346
struct mptcpd_plugin_ops const *ops);
347347

348+
MPTCPD_API bool mptcpd_plugin_read_config(char const *filename,
349+
mptcpd_parse_func_t fun,
350+
void *user_data);
351+
348352
#ifdef __cplusplus
349353
}
350354
#endif

include/mptcpd/private/plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct mptcpd_interface;
4242
*/
4343
MPTCPD_API bool mptcpd_plugin_load(char const *dir,
4444
char const *default_name,
45+
char const *plugins_conf_dir,
4546
struct l_queue const *plugins_to_load,
4647
struct mptcpd_pm *pm);
4748

lib/plugin.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# define MPTCP_PM_NAME_LEN GENL_NAMSIZ
4040
#endif
4141

42+
#include <mptcpd/private/configuration.h>
4243
#include <mptcpd/private/plugin.h>
4344
#include <mptcpd/plugin.h>
4445

@@ -86,6 +87,8 @@ static char _default_name[MPTCP_PM_NAME_LEN + 1];
8687
*/
8788
static struct mptcpd_plugin_ops const *_default_ops;
8889

90+
static char *_conf_dir;
91+
8992
// ----------------------------------------------------------------
9093
// Implementation Details
9194
// ----------------------------------------------------------------
@@ -432,6 +435,7 @@ static void unload_plugins(struct mptcpd_pm *pm)
432435

433436
bool mptcpd_plugin_load(char const *dir,
434437
char const *default_name,
438+
char const *plugins_conf_dir,
435439
struct l_queue const *plugins_to_load,
436440
struct mptcpd_pm *pm)
437441
{
@@ -440,6 +444,14 @@ bool mptcpd_plugin_load(char const *dir,
440444
return false;
441445
}
442446

447+
if (plugins_conf_dir == NULL) {
448+
l_error("No plugins configuration directory specified.");
449+
return false;
450+
}
451+
452+
if (_conf_dir == NULL)
453+
_conf_dir = l_strdup(plugins_conf_dir);
454+
443455
if (_plugin_infos == NULL)
444456
_plugin_infos = l_queue_new();
445457

@@ -569,6 +581,25 @@ bool mptcpd_plugin_register_ops(char const *name,
569581
return registered;
570582
}
571583

584+
bool mptcpd_plugin_read_config(char const *filename,
585+
mptcpd_parse_func_t fun,
586+
void *user_data)
587+
{
588+
assert(filename != NULL);
589+
assert(fun != NULL);
590+
591+
char *const path = l_strdup_printf("%s/%s.conf",
592+
_conf_dir,
593+
filename);
594+
595+
bool success = mptcpd_config_read(path, fun, user_data);
596+
597+
l_free(path);
598+
599+
return success;
600+
}
601+
602+
572603
// ----------------------------------------------------------------
573604
// Plugin Operation Callback Invocation
574605
// ----------------------------------------------------------------

src/path_manager.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ static void complete_pm_init(void *data)
826826
*/
827827
if (!mptcpd_plugin_load(pm->config->plugin_dir,
828828
pm->config->default_plugin,
829+
pm->config->plugins_conf_dir,
829830
pm->config->plugins_to_load,
830831
pm)) {
831832
l_error("Unable to load path manager plugins.");

0 commit comments

Comments
 (0)