From 5fb53acfea44608d4574fa7c93529e18aae42142 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 12 Dec 2007 15:17:08 +0000 Subject: [PATCH] Implement Plugin Directory and plugin events. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6042 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dird_conf.c | 1 + bacula/src/dird/dird_conf.h | 1 + bacula/src/filed/filed_conf.c | 3 ++- bacula/src/filed/filed_conf.h | 1 + bacula/src/lib/plugin.c | 4 +-- bacula/src/lib/plugin.h | 5 ++-- bacula/src/plugins/fd/main.c | 44 ++++++++++++++++++++++--------- bacula/src/plugins/fd/plugin-fd.c | 15 ++++++++--- bacula/src/plugins/fd/plugin-fd.h | 15 +++++++++-- bacula/src/stored/stored_conf.c | 1 + bacula/src/stored/stored_conf.h | 1 + bacula/technotes-2.3 | 2 ++ 12 files changed, 71 insertions(+), 22 deletions(-) diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 04312c14cd..eebb9601a8 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -114,6 +114,7 @@ static RES_ITEM dir_items[] = { {"diraddresses",store_addresses, ITEM(res_dir.DIRaddrs), 0, ITEM_DEFAULT, 9101}, {"queryfile", store_dir, ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0}, {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0}, + {"plugindirectory", store_dir, ITEM(res_dir.plugin_directory), 0, 0, 0}, {"scriptsdirectory", store_dir, ITEM(res_dir.scripts_directory), 0, 0, 0}, {"piddirectory",store_dir, ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0}, {"subsysdirectory", store_dir, ITEM(res_dir.subsys_directory), 0, 0, 0}, diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index f8d91cacc8..dffce56428 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -110,6 +110,7 @@ public: char *query_file; /* SQL query file */ char *working_directory; /* WorkingDirectory */ const char *scripts_directory; /* ScriptsDirectory */ + const char *plugin_directory; /* Plugin Directory */ char *pid_directory; /* PidDirectory */ char *subsys_directory; /* SubsysDirectory */ MSGS *messages; /* Daemon message handler */ diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index a7ce38b564..ac4f92726e 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -95,7 +95,8 @@ static RES_ITEM cli_items[] = { {"workingdirectory", store_dir, ITEM(res_client.working_directory), 0, ITEM_REQUIRED, 0}, {"piddirectory", store_dir, ITEM(res_client.pid_directory), 0, ITEM_REQUIRED, 0}, {"subsysdirectory", store_dir, ITEM(res_client.subsys_directory), 0, 0, 0}, - {"scriptsdirectory", store_dir, ITEM(res_client.scripts_directory), 0, 0, 0}, + {"plugindirectory", store_dir, ITEM(res_client.plugin_directory), 0, 0, 0}, + {"scriptsdirectory", store_dir, ITEM(res_client.scripts_directory), 0, 0, 0}, {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 20}, {"messages", store_res, ITEM(res_client.messages), R_MSGS, 0, 0}, {"sdconnecttimeout", store_time,ITEM(res_client.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30}, diff --git a/bacula/src/filed/filed_conf.h b/bacula/src/filed/filed_conf.h index 2efbb2a2b0..776a9e0c7f 100644 --- a/bacula/src/filed/filed_conf.h +++ b/bacula/src/filed/filed_conf.h @@ -79,6 +79,7 @@ struct CLIENT { char *working_directory; char *pid_directory; char *subsys_directory; + char *plugin_directory; /* Plugin directory */ char *scripts_directory; MSGS *messages; /* daemon message handler */ int MaxConcurrentJobs; diff --git a/bacula/src/lib/plugin.c b/bacula/src/lib/plugin.c index c6762620ec..8c28f13068 100644 --- a/bacula/src/lib/plugin.c +++ b/bacula/src/lib/plugin.c @@ -56,7 +56,7 @@ Plugin *new_plugin() /* * Load all the plugins in the specified directory. */ -bool load_plugins(void *bfuncs, const char *plugin_dir, const char *type) +bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char *type) { t_loadPlugin loadPlugin; Plugin *plugin; @@ -140,7 +140,7 @@ bool load_plugins(void *bfuncs, const char *plugin_dir, const char *type) } /* Initialize the plugin */ - loadPlugin(bfuncs, &plugin->pfuncs); + loadPlugin(binfo, bfuncs, &plugin->pinfo, &plugin->pfuncs); found = true; /* found a plugin */ } diff --git a/bacula/src/lib/plugin.h b/bacula/src/lib/plugin.h index 0ff939955a..9c10e32c16 100644 --- a/bacula/src/lib/plugin.h +++ b/bacula/src/lib/plugin.h @@ -66,7 +66,7 @@ typedef struct s_bpContext { } bpContext; extern "C" { -typedef bpError (*t_loadPlugin)(void *bfuncs, void **pfuncs); +typedef bpError (*t_loadPlugin)(void *binfo, void *bfuncs, void **pinfo, void **pfuncs); typedef bpError (*t_unloadPlugin)(void); } @@ -74,13 +74,14 @@ class Plugin { public: char *file; t_unloadPlugin unloadPlugin; + void *pinfo; void *pfuncs; void *pHandle; }; /* Functions */ extern Plugin *new_plugin(); -extern bool load_plugins(void *bfuncs, const char *plugin_dir, const char *type); +extern bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char *type); extern void unload_plugins(); diff --git a/bacula/src/plugins/fd/main.c b/bacula/src/plugins/fd/main.c index eae0a818df..3333a912aa 100644 --- a/bacula/src/plugins/fd/main.c +++ b/bacula/src/plugins/fd/main.c @@ -42,16 +42,23 @@ const char *plugin_type = "-fd.so"; /* Forward referenced functions */ static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value); static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value); +static bpError baculaRegisterEvents(bpContext *ctx, ...); +/* Bacula info */ +static bInfo binfo = { + sizeof(bFuncs), + PLUGIN_INTERFACE, +}; /* Bacula entry points */ static bFuncs bfuncs = { sizeof(bFuncs), PLUGIN_INTERFACE, + baculaRegisterEvents, baculaGetValue, baculaSetValue, NULL, - NULL + NULL, }; @@ -70,29 +77,29 @@ int main(int argc, char *argv[]) ctx.pContext = NULL; getcwd(plugin_dir, sizeof(plugin_dir)-1); - load_plugins((void *)&bfuncs, plugin_dir, plugin_type); + load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type); foreach_alist(plugin, plugin_list) { printf("bacula: plugin_size=%d plugin_version=%d\n", - pref(plugin)->size, pref(plugin)->interface); + plug_func(plugin)->size, plug_func(plugin)->interface); printf("License: %s\nAuthor: %s\nDate: %s\nVersion: %s\nDescription: %s\n", - pref(plugin)->plugin_license, pref(plugin)->plugin_author, - pref(plugin)->plugin_date, pref(plugin)->plugin_version, - pref(plugin)->plugin_description); + plug_info(plugin)->plugin_license, plug_info(plugin)->plugin_author, + plug_info(plugin)->plugin_date, plug_info(plugin)->plugin_version, + plug_info(plugin)->plugin_description); /* Start a new instance of the plugin */ - pref(plugin)->newPlugin(&ctx); + plug_func(plugin)->newPlugin(&ctx); event.eventType = bEventNewVolume; - pref(plugin)->handlePluginEvent(&ctx, &event); + plug_func(plugin)->handlePluginEvent(&ctx, &event); /* Free the plugin instance */ - pref(plugin)->freePlugin(&ctx); + plug_func(plugin)->freePlugin(&ctx); /* Start a new instance of the plugin */ - pref(plugin)->newPlugin(&ctx); + plug_func(plugin)->newPlugin(&ctx); event.eventType = bEventNewVolume; - pref(plugin)->handlePluginEvent(&ctx, &event); + plug_func(plugin)->handlePluginEvent(&ctx, &event); /* Free the plugin instance */ - pref(plugin)->freePlugin(&ctx); + plug_func(plugin)->freePlugin(&ctx); } unload_plugins(); @@ -117,3 +124,16 @@ static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value) printf("bacula: baculaSetValue var=%d\n", var); return 0; } + +static bpError baculaRegisterEvents(bpContext *ctx, ...) +{ + va_list args; + uint32_t event; + + va_start(args, ctx); + while ((event = va_arg(args, uint32_t))) { + printf("Plugin wants event=%u\n", event); + } + va_end(args); + return 0; +} diff --git a/bacula/src/plugins/fd/plugin-fd.c b/bacula/src/plugins/fd/plugin-fd.c index 3181d94a8d..a00d384b1c 100644 --- a/bacula/src/plugins/fd/plugin-fd.c +++ b/bacula/src/plugins/fd/plugin-fd.c @@ -54,9 +54,10 @@ static bpError handlePluginEvent(bpContext *ctx, bEvent *event); /* Pointers to Bacula functions */ static bFuncs *bfuncs = NULL; +static bInfo *binfo = NULL; -static pFuncs pluginFuncs = { - sizeof(pluginFuncs), +static pInfo pluginInfo = { + sizeof(pluginInfo), PLUGIN_INTERFACE, PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -64,6 +65,11 @@ static pFuncs pluginFuncs = { PLUGIN_DATE, PLUGIN_VERSION, PLUGIN_DESCRIPTION, +}; + +static pFuncs pluginFuncs = { + sizeof(pluginFuncs), + PLUGIN_INTERFACE, /* Entry points into plugin */ newPlugin, /* new plugin instance */ @@ -73,11 +79,13 @@ static pFuncs pluginFuncs = { handlePluginEvent }; -bpError loadPlugin(bFuncs *lbfuncs, pFuncs **pfuncs) +bpError loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs) { bfuncs = lbfuncs; /* set Bacula funct pointers */ + binfo = lbinfo; printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->interface); + *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ return 0; @@ -94,6 +102,7 @@ static bpError newPlugin(bpContext *ctx) int JobId = 0; bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId); printf("plugin: newPlugin JobId=%d\n", JobId); + bfuncs->registerBaculaEvents(ctx, 1, 2, 0); return 0; } diff --git a/bacula/src/plugins/fd/plugin-fd.h b/bacula/src/plugins/fd/plugin-fd.h index cc78a42cb6..2f1010bae5 100644 --- a/bacula/src/plugins/fd/plugin-fd.h +++ b/bacula/src/plugins/fd/plugin-fd.h @@ -73,11 +73,16 @@ typedef struct s_bEvent { uint32_t eventType; } bEvent; +typedef struct s_baculaInfo { + uint32_t size; + uint32_t interface; +} bInfo; /* Bacula interface version and function pointers */ typedef struct s_baculaFuncs { uint32_t size; uint32_t interface; + bpError (*registerBaculaEvents)(bpContext *ctx, ...); bpError (*getBaculaValue)(bpContext *ctx, bVariable var, void *value); bpError (*setBaculaValue)(bpContext *ctx, bVariable var, void *value); bpError (*allocBaculaMem)(bpContext *ctx, uint32_t size, char *addr); @@ -100,7 +105,7 @@ typedef enum { #define PLUGIN_MAGIC "*PluginData*" #define PLUGIN_INTERFACE 1 -typedef struct s_pluginFuncs { +typedef struct s_pluginInfo { uint32_t size; uint32_t interface; char *plugin_magic; @@ -109,6 +114,11 @@ typedef struct s_pluginFuncs { char *plugin_date; char *plugin_version; char *plugin_description; +} pInfo; + +typedef struct s_pluginFuncs { + uint32_t size; + uint32_t interface; bpError (*newPlugin)(bpContext *ctx); bpError (*freePlugin)(bpContext *ctx); bpError (*getPluginValue)(bpContext *ctx, pVariable var, void *value); @@ -116,7 +126,8 @@ typedef struct s_pluginFuncs { bpError (*handlePluginEvent)(bpContext *ctx, bEvent *event); } pFuncs; -#define pref(plugin) ((pFuncs *)(plugin->pfuncs)) +#define plug_func(plugin) ((pFuncs *)(plugin->pfuncs)) +#define plug_info(plugin) ((pInfo *)(plugin->pinfo)) #ifdef __cplusplus } diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index 0c96fd27c9..8f79c44ffc 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -74,6 +74,7 @@ static RES_ITEM store_items[] = { {"workingdirectory", store_dir, ITEM(res_store.working_directory), 0, ITEM_REQUIRED, 0}, {"piddirectory", store_dir, ITEM(res_store.pid_directory), 0, ITEM_REQUIRED, 0}, {"subsysdirectory", store_dir, ITEM(res_store.subsys_directory), 0, 0, 0}, + {"plugindirectory", store_dir, ITEM(res_store.plugin_directory), 0, 0, 0}, {"scriptsdirectory", store_dir, ITEM(res_store.scripts_directory), 0, 0, 0}, {"maximumconcurrentjobs", store_pint, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 20}, {"heartbeatinterval", store_time, ITEM(res_store.heartbeat_interval), 0, ITEM_DEFAULT, 0}, diff --git a/bacula/src/stored/stored_conf.h b/bacula/src/stored/stored_conf.h index 70b6126869..679ccfb58f 100644 --- a/bacula/src/stored/stored_conf.h +++ b/bacula/src/stored/stored_conf.h @@ -83,6 +83,7 @@ public: char *working_directory; /* working directory for checkpoints */ char *pid_directory; char *subsys_directory; + char *plugin_directory; /* Plugin directory */ char *scripts_directory; uint32_t max_concurrent_jobs; /* maximum concurrent jobs to run */ MSGS *messages; /* Daemon message handler */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index b12efcb1ec..e36f77ae65 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,8 @@ Technical notes on version 2.3 General: +12Dec07 +kes Implement Plugin Directory and plugin events. 11Dec07 kes Implement a security enhancement: TLS authentication but no encryption. Enabled by setting 'TLS Authentication = yes'. -- 2.39.5