From: Kern Sibbald Date: Sat, 8 Mar 2008 15:09:10 +0000 (+0000) Subject: Plugin work -- bring dir up to fd level. X-Git-Tag: Release-3.0.0~1733 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e8e1c24a67fc6a6171ba6399b318996ae76b5219;p=bacula%2Fbacula Plugin work -- bring dir up to fd level. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6557 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/dir-plugins.c b/bacula/src/dird/dir-plugins.c index 53eaa3e6d8..1821c593ff 100644 --- a/bacula/src/dird/dir-plugins.c +++ b/bacula/src/dird/dir-plugins.c @@ -32,8 +32,7 @@ * Kern Sibbald, October 2007 */ #include "bacula.h" -#include "jcr.h" -#include "dir-plugins.h" +#include "dird.h" const int dbglvl = 0; const char *plugin_type = "-dir.so"; @@ -52,13 +51,13 @@ static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line, /* Bacula info */ static bInfo binfo = { sizeof(bFuncs), - PLUGIN_INTERFACE, + DIR_PLUGIN_INTERFACE_VERSION, }; /* Bacula entry points */ static bFuncs bfuncs = { sizeof(bFuncs), - PLUGIN_INTERFACE, + DIR_PLUGIN_INTERFACE_VERSION, baculaRegisterEvents, baculaGetValue, baculaSetValue, @@ -69,7 +68,7 @@ static bFuncs bfuncs = { /* * Create a plugin event */ -void generate_plugin_event(JCR *jcr, bEventType eventType) +void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { bEvent event; Plugin *plugin; @@ -80,11 +79,19 @@ void generate_plugin_event(JCR *jcr, bEventType eventType) } bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; - Dmsg2(dbglvl, "plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); event.eventType = eventType; + + Dmsg2(dbglvl, "plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); + foreach_alist(plugin, plugin_list) { - plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i++], &event); + bRC rc; + rc = plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i++], &event, value); + if (rc != bRC_OK) { + break; + } } + + return; } void load_dir_plugins(const char *plugin_dir) @@ -231,9 +238,9 @@ int main(int argc, char *argv[]) jcr2->JobId = 222; new_plugins(jcr2); - generate_plugin_event(jcr1, bEventJobStart); + generate_plugin_event(jcr1, bEventJobStart, (void *)"Start Job 1"); generate_plugin_event(jcr1, bEventJobEnd); - generate_plugin_event(jcr2, bEventJobStart); + generate_plugin_event(jcr2, bEventJobStart, (void *)"Start Job 1"); free_plugins(jcr1); generate_plugin_event(jcr2, bEventJobEnd); free_plugins(jcr2); diff --git a/bacula/src/dird/dir-plugins.h b/bacula/src/dird/dir-plugins.h index 220b26882d..0e77dbf902 100644 --- a/bacula/src/dird/dir-plugins.h +++ b/bacula/src/dird/dir-plugins.h @@ -35,6 +35,19 @@ #ifndef __FD_PLUGINS_H #define __FD_PLUGINS_H +#ifndef _BACULA_H +#ifdef __cplusplus +/* Workaround for SGI IRIX 6.5 */ +#define _LANGUAGE_C_PLUS_PLUS 1 +#endif +#define _REENTRANT 1 +#define _THREAD_SAFE 1 +#define _POSIX_PTHREAD_SEMANTICS 1 +#define _FILE_OFFSET_BITS 64 +#define _LARGEFILE_SOURCE 1 +#define _LARGE_FILES 1 +#endif + #include #ifndef __CONFIG_H #define __CONFIG_H @@ -120,7 +133,7 @@ typedef struct s_baculaFuncs { void load_dir_plugins(const char *plugin_dir); void new_plugins(JCR *jcr); void free_plugins(JCR *jcr); -void generate_plugin_event(JCR *jcr, bEventType event); +void generate_plugin_event(JCR *jcr, bEventType event, void *value=NULL); @@ -136,8 +149,8 @@ typedef enum { } pVariable; -#define PLUGIN_MAGIC "*PluginData*" -#define PLUGIN_INTERFACE 1 +#define DIR_PLUGIN_MAGIC "*DirPluginData*" +#define DIR_PLUGIN_INTERFACE_VERSION 1 typedef struct s_pluginInfo { uint32_t size; @@ -157,7 +170,7 @@ typedef struct s_pluginFuncs { bRC (*freePlugin)(bpContext *ctx); bRC (*getPluginValue)(bpContext *ctx, pVariable var, void *value); bRC (*setPluginValue)(bpContext *ctx, pVariable var, void *value); - bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event); + bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value); } pFuncs; #define plug_func(plugin) ((pFuncs *)(plugin->pfuncs)) diff --git a/bacula/src/filed/fd-plugins.c b/bacula/src/filed/fd-plugins.c index 116b6799fe..e99ce1fedc 100644 --- a/bacula/src/filed/fd-plugins.c +++ b/bacula/src/filed/fd-plugins.c @@ -39,7 +39,6 @@ const char *plugin_type = "-fd.so"; extern int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level); - /* Function pointers to be set here */ extern DLL_IMP_EXP int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode); extern DLL_IMP_EXP int (*plugin_bclose)(JCR *jcr); @@ -67,13 +66,13 @@ static boffset_t my_plugin_blseek(JCR *jcr, boffset_t offset, int whence); /* Bacula info */ static bInfo binfo = { sizeof(bFuncs), - PLUGIN_INTERFACE_VERSION + FD_PLUGIN_INTERFACE_VERSION }; /* Bacula entry points */ static bFuncs bfuncs = { sizeof(bFuncs), - PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_INTERFACE_VERSION, baculaRegisterEvents, baculaGetValue, baculaSetValue, @@ -333,6 +332,9 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) rp.attrEx = attr->attrEx; rp.ofname = attr->ofname; rp.olname = attr->olname; + rp.where = jcr->where; + rp.RegexWhere = jcr->RegexWhere; + rp.replace = jcr->replace; if (plug_func(plugin)->createFile(plugin_ctx, &rp) != bRC_OK) { return CF_ERROR; } @@ -365,6 +367,8 @@ void load_fd_plugins(const char *plugin_dir) plugin_list = New(alist(10, not_owned_by_alist)); load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type); + + /* Plug entry points called from findlib */ plugin_bopen = my_plugin_bopen; plugin_bclose = my_plugin_bclose; plugin_bread = my_plugin_bread; @@ -608,9 +612,9 @@ int main(int argc, char *argv[]) jcr2->JobId = 222; new_plugins(jcr2); - generate_plugin_event(jcr1, bEventJobStart); + generate_plugin_event(jcr1, bEventJobStart, (void *)"Start Job 1"); generate_plugin_event(jcr1, bEventJobEnd); - generate_plugin_event(jcr2, bEventJobStart); + generate_plugin_event(jcr2, bEventJobStart, (void *)"Start Job 2"); free_plugins(jcr1); generate_plugin_event(jcr2, bEventJobEnd); free_plugins(jcr2); diff --git a/bacula/src/filed/fd-plugins.h b/bacula/src/filed/fd-plugins.h index c88392a540..099862d038 100644 --- a/bacula/src/filed/fd-plugins.h +++ b/bacula/src/filed/fd-plugins.h @@ -84,6 +84,9 @@ struct restore_pkt { const char *attrEx; /* extended attributes if any */ const char *ofname; /* output filename */ const char *olname; /* output link name */ + const char *where; /* where */ + const char *RegexWhere; /* regex where */ + int replace; /* replace flag */ }; enum { @@ -196,8 +199,8 @@ typedef enum { } pVariable; -#define PLUGIN_MAGIC "*PluginData*" -#define PLUGIN_INTERFACE_VERSION 1 +#define FD_PLUGIN_MAGIC "*FDPluginData*" +#define FD_PLUGIN_INTERFACE_VERSION 1 typedef struct s_pluginInfo { uint32_t size; diff --git a/bacula/src/plugins/dir/Makefile b/bacula/src/plugins/dir/Makefile index 97e4dbb052..8645dace37 100644 --- a/bacula/src/plugins/dir/Makefile +++ b/bacula/src/plugins/dir/Makefile @@ -1,25 +1,31 @@ # -# Simple Makefile for building test Director plugins for Bacula +# Simple Makefile for building test Dir plugins for Bacula # # No optimization for now for easy debugging CC = g++ -g -O0 -Wall +DIRDIR=../../dird +SRCDIR=../.. +LIBDIR=../../lib + .SUFFIXES: .c .o .c.o: - $(CC) -I../.. -DTEST_PROGRAM -c $< + $(CC) -I${SRCDIR} -I${DIRDIR} -DTEST_PROGRAM -c $< + +test: main example-plugin-dir.so -all: dir-plugins example-plugin-dir.so +dir-plugins.o: ${DIRDIR}/dir-plugins.h ${DIRDIR}/dir-plugins.c + $(CC) -I${SRCDIR} -I${DIRDIR} -DTEST_PROGRAM -c ${DIRDIR}/dir-plugins.c -dir-plugins: dir-plugins.o dir-plugins.h - $(CC) -L../../lib dir-plugins.o -o main -lbac -lpthread -lssl -l crypto -ldl +main: dir-plugins.o + $(CC) -L${LIBDIR} dir-plugins.o -o main -lbac -lpthread -lssl -l crypto -ldl -example-plugin-dir.o: example-plugin-dir.c dir-plugins.h - $(CC) -fPIC -I../.. -c example-plugin-dir.c +example-plugin-dir.o: example-plugin-dir.c ${DIRDIR}/dir-plugins.h + $(CC) -fPIC -I../.. -I${DIRDIR} -c example-plugin-dir.c example-plugin-dir.so: example-plugin-dir.o $(CC) -shared example-plugin-dir.o -o example-plugin-dir.so - clean: rm -f main *.so *.o 1 2 3 diff --git a/bacula/src/plugins/dir/dir-plugins.c b/bacula/src/plugins/dir/dir-plugins.c deleted file mode 100644 index 69518b9f42..0000000000 --- a/bacula/src/plugins/dir/dir-plugins.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2007-2008 Free Software Foundation Europe e.V. - - The main author of Bacula is Kern Sibbald, with contributions from - many others, a complete list can be found in the file AUTHORS. - This program is Free Software; you can redistribute it and/or - modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation, which is - listed in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - Bacula® is a registered trademark of John Walker. - The licensor of Bacula is the Free Software Foundation Europe - (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, - Switzerland, email:ftf@fsfeurope.org. -*/ -/* - * Main program to test loading and running Bacula plugins. - * Destined to become Bacula pluginloader, ... - * - * Kern Sibbald, October 2007 - */ -#include "bacula.h" -#include "jcr.h" -#include "dir-plugins.h" - -const int dbglvl = 0; -const char *plugin_type = "-dir.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, ...); -static bpError baculaJobMsg(bpContext *ctx, const char *file, int line, - int type, time_t mtime, const char *msg); -static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line, - int level, const char *msg); - - -/* Bacula info */ -static bInfo binfo = { - sizeof(bFuncs), - PLUGIN_INTERFACE, -}; - -/* Bacula entry points */ -static bFuncs bfuncs = { - sizeof(bFuncs), - PLUGIN_INTERFACE, - baculaRegisterEvents, - baculaGetValue, - baculaSetValue, - baculaJobMsg, - baculaDebugMsg -}; - -/* - * Create a plugin event - */ -void generate_plugin_event(JCR *jcr, bEventType eventType) -{ - bEvent event; - Plugin *plugin; - int i = 0; - - if (!plugin_list) { - return; - } - - bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; - Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); - event.eventType = eventType; - foreach_alist(plugin, plugin_list) { - plug_func(plugin)->handlePluginEvent(&plugin_ctx[i++], &event); - } -} - -void load_dir_plugins(const char *plugin_dir) -{ - if (!plugin_dir) { - return; - } - - plugin_list = New(alist(10, not_owned_by_alist)); - load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type); -} - -/* - * Create a new instance of each plugin for this Job - */ -void new_plugins(JCR *jcr) -{ - Plugin *plugin; - int i = 0; - - if (!plugin_list) { - return; - } - - int num = plugin_list->size(); - - if (num == 0) { - return; - } - - jcr->plugin_ctx = (void *)malloc(sizeof(bpContext) * num); - - bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; - Dmsg2(dbglvl, "Instantiate plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); - foreach_alist(plugin, plugin_list) { - /* Start a new instance of each plugin */ - plugin_ctx[i].bContext = (void *)jcr; - plugin_ctx[i].pContext = NULL; - plug_func(plugin)->newPlugin(&plugin_ctx[i++]); - } -} - -/* - * Free the plugin instances for this Job - */ -void free_plugins(JCR *jcr) -{ - Plugin *plugin; - int i = 0; - - if (!plugin_list) { - return; - } - - bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; - Dmsg2(dbglvl, "Free instance plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); - foreach_alist(plugin, plugin_list) { - /* Free the plugin instance */ - plug_func(plugin)->freePlugin(&plugin_ctx[i++]); - } - free(plugin_ctx); - jcr->plugin_ctx = NULL; -} - - -/* ============================================================== - * - * Callbacks from the plugin - * - * ============================================================== - */ -static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value) -{ - JCR *jcr = (JCR *)(ctx->bContext); -// Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var); - if (!value) { - return 1; - } -// Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr); - switch (var) { - case bVarJobId: - *((int *)value) = jcr->JobId; - Dmsg1(dbglvl, "Bacula: return bVarJobId=%d\n", jcr->JobId); - break; - case bVarFDName: - *((char **)value) = my_name; - Dmsg1(dbglvl, "Bacula: return my_name=%s\n", my_name); - break; - case bVarLevel: - case bVarType: - case bVarClient: - case bVarJobName: - case bVarJobStatus: - case bVarSinceTime: - break; - } - return 0; -} - -static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value) -{ - Dmsg1(dbglvl, "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))) { - Dmsg1(dbglvl, "Plugin wants event=%u\n", event); - } - va_end(args); - return 0; -} - -static bpError baculaJobMsg(bpContext *ctx, const char *file, int line, - int type, time_t mtime, const char *msg) -{ - Dmsg5(dbglvl, "Job message: %s:%d type=%d time=%ld msg=%s\n", - file, line, type, mtime, msg); - return 0; -} - -static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line, - int level, const char *msg) -{ - Dmsg4(dbglvl, "Debug message: %s:%d level=%d msg=%s\n", - file, line, level, msg); - return 0; -} - -#ifdef TEST_PROGRAM - - -int main(int argc, char *argv[]) -{ - char plugin_dir[1000]; - JCR mjcr1, mjcr2; - JCR *jcr1 = &mjcr1; - JCR *jcr2 = &mjcr2; - - strcpy(my_name, "test-dir"); - - getcwd(plugin_dir, sizeof(plugin_dir)-1); - load_dir_plugins(plugin_dir); - - jcr1->JobId = 111; - new_plugins(jcr1); - - jcr2->JobId = 222; - new_plugins(jcr2); - - generate_plugin_event(jcr1, bEventJobStart); - generate_plugin_event(jcr1, bEventJobEnd); - generate_plugin_event(jcr2, bEventJobStart); - free_plugins(jcr1); - generate_plugin_event(jcr2, bEventJobEnd); - free_plugins(jcr2); - - unload_plugins(); - - Dmsg0(dbglvl, "bacula: OK ...\n"); - close_memory_pool(); - sm_dump(false); - return 0; -} - -#endif /* TEST_PROGRAM */ diff --git a/bacula/src/plugins/dir/dir-plugins.h b/bacula/src/plugins/dir/dir-plugins.h deleted file mode 100644 index e25b3265c4..0000000000 --- a/bacula/src/plugins/dir/dir-plugins.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2007-2008 Free Software Foundation Europe e.V. - - The main author of Bacula is Kern Sibbald, with contributions from - many others, a complete list can be found in the file AUTHORS. - This program is Free Software; you can redistribute it and/or - modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation, which is - listed in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - Bacula® is a registered trademark of John Walker. - The licensor of Bacula is the Free Software Foundation Europe - (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, - Switzerland, email:ftf@fsfeurope.org. -*/ -/* - * Interface definition for Bacula Plugins - * - * Kern Sibbald, October 2007 - * - */ - -#ifndef __FD_PLUGINS_H -#define __FD_PLUGINS_H - -#include -#ifndef __CONFIG_H -#define __CONFIG_H -#include "config.h" -#endif -#include "bc_types.h" -#include "lib/plugins.h" - -#ifdef __cplusplus -extern "C" { -#endif - - - - -/**************************************************************************** - * * - * Bacula definitions * - * * - ****************************************************************************/ - -/* Bacula Variable Ids */ -typedef enum { - bVarJobId = 1, - bVarFDName = 2, - bVarLevel = 3, - bVarType = 4, - bVarClient = 5, - bVarJobName = 6, - bVarJobStatus = 7, - bVarSinceTime = 8 -} bVariable; - -typedef enum { - bEventJobStart = 1, - bEventJobEnd = 2, -} bEventType; - -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 (*JobMessage)(bpContext *ctx, const char *file, int line, - int type, time_t mtime, const char *msg); - bpError (*DebugMessage)(bpContext *ctx, const char *file, int line, - int level, const char *msg); -} bFuncs; - -/* Bacula Subroutines */ -void load_dir_plugins(const char *plugin_dir); -void new_plugins(JCR *jcr); -void free_plugins(JCR *jcr); -void generate_plugin_event(JCR *jcr, bEventType event); - - - -/**************************************************************************** - * * - * Plugin definitions * - * * - ****************************************************************************/ - -typedef enum { - pVarName = 1, - pVarDescription = 2 -} pVariable; - - -#define PLUGIN_MAGIC "*PluginData*" -#define PLUGIN_INTERFACE 1 - -typedef struct s_pluginInfo { - uint32_t size; - uint32_t interface; - char *plugin_magic; - char *plugin_license; - char *plugin_author; - 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); - bpError (*setPluginValue)(bpContext *ctx, pVariable var, void *value); - bpError (*handlePluginEvent)(bpContext *ctx, bEvent *event); -} pFuncs; - -#define plug_func(plugin) ((pFuncs *)(plugin->pfuncs)) -#define plug_info(plugin) ((pInfo *)(plugin->pinfo)) - -#ifdef __cplusplus -} -#endif - -#endif /* __FD_PLUGINS_H */ diff --git a/bacula/src/plugins/dir/example-plugin-dir.c b/bacula/src/plugins/dir/example-plugin-dir.c index f58679ff60..d98f120363 100644 --- a/bacula/src/plugins/dir/example-plugin-dir.c +++ b/bacula/src/plugins/dir/example-plugin-dir.c @@ -45,11 +45,11 @@ extern "C" { #define PLUGIN_DESCRIPTION "Test File Daemon Plugin" /* Forward referenced functions */ -static bpError newPlugin(bpContext *ctx); -static bpError freePlugin(bpContext *ctx); -static bpError getPluginValue(bpContext *ctx, pVariable var, void *value); -static bpError setPluginValue(bpContext *ctx, pVariable var, void *value); -static bpError handlePluginEvent(bpContext *ctx, bEvent *event); +static bRC newPlugin(bpContext *ctx); +static bRC freePlugin(bpContext *ctx); +static bRC getPluginValue(bpContext *ctx, pVariable var, void *value); +static bRC setPluginValue(bpContext *ctx, pVariable var, void *value); +static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value); /* Pointers to Bacula functions */ @@ -58,8 +58,8 @@ static bInfo *binfo = NULL; static pInfo pluginInfo = { sizeof(pluginInfo), - PLUGIN_INTERFACE, - PLUGIN_MAGIC, + DIR_PLUGIN_INTERFACE_VERSION, + DIR_PLUGIN_MAGIC, PLUGIN_LICENSE, PLUGIN_AUTHOR, PLUGIN_DATE, @@ -69,7 +69,7 @@ static pInfo pluginInfo = { static pFuncs pluginFuncs = { sizeof(pluginFuncs), - PLUGIN_INTERFACE, + DIR_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ newPlugin, /* new plugin instance */ @@ -79,54 +79,54 @@ static pFuncs pluginFuncs = { handlePluginEvent }; -bpError loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs) +bRC 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); + printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version); *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ - return 0; + return bRC_OK; } -bpError unloadPlugin() +bRC unloadPlugin() { printf("plugin: Unloaded\n"); - return 0; + return bRC_OK; } -static bpError newPlugin(bpContext *ctx) +static bRC 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; + return bRC_OK; } -static bpError freePlugin(bpContext *ctx) +static bRC freePlugin(bpContext *ctx) { int JobId = 0; bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId); printf("plugin: freePlugin JobId=%d\n", JobId); - return 0; + return bRC_OK; } -static bpError getPluginValue(bpContext *ctx, pVariable var, void *value) +static bRC getPluginValue(bpContext *ctx, pVariable var, void *value) { printf("plugin: getPluginValue var=%d\n", var); - return 0; + return bRC_OK; } -static bpError setPluginValue(bpContext *ctx, pVariable var, void *value) +static bRC setPluginValue(bpContext *ctx, pVariable var, void *value) { printf("plugin: setPluginValue var=%d\n", var); - return 0; + return bRC_OK; } -static bpError handlePluginEvent(bpContext *ctx, bEvent *event) +static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { char *name; switch (event->eventType) { @@ -137,11 +137,11 @@ static bpError handlePluginEvent(bpContext *ctx, bEvent *event) printf("plugin: HandleEvent JobEnd\n"); break; } - bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name); - printf("FD Name=%s\n", name); + bfuncs->getBaculaValue(ctx, bVarJobName, (void *)&name); + printf("Job Name=%s\n", name); bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message"); bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message"); - return 0; + return bRC_OK; } #ifdef __cplusplus diff --git a/bacula/src/plugins/fd/Makefile b/bacula/src/plugins/fd/Makefile index 943126ba2b..8a27f1ec1d 100644 --- a/bacula/src/plugins/fd/Makefile +++ b/bacula/src/plugins/fd/Makefile @@ -1,5 +1,5 @@ # -# Simple Makefile for building test plugin-fds for Bacula +# Simple Makefile for building test FD plugins for Bacula # # No optimization for now for easy debugging @@ -11,7 +11,7 @@ LIBDIR=../../lib .SUFFIXES: .c .o .c.o: - $(CC) -I${SRCDIR} -I${FDDOR} -DTEST_PROGRAM -c $< + $(CC) -I${SRCDIR} -I${FDDIR} -DTEST_PROGRAM -c $< all: bpipe-fd.so diff --git a/bacula/src/plugins/fd/bpipe-fd.c b/bacula/src/plugins/fd/bpipe-fd.c index 66f83c2143..71f384c2dd 100644 --- a/bacula/src/plugins/fd/bpipe-fd.c +++ b/bacula/src/plugins/fd/bpipe-fd.c @@ -69,8 +69,8 @@ static bInfo *binfo = NULL; /* Plugin Information block */ static pInfo pluginInfo = { sizeof(pluginInfo), - PLUGIN_INTERFACE_VERSION, - PLUGIN_MAGIC, + FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, PLUGIN_AUTHOR, PLUGIN_DATE, @@ -81,7 +81,7 @@ static pInfo pluginInfo = { /* Plugin entry points for Bacula */ static pFuncs pluginFuncs = { sizeof(pluginFuncs), - PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ newPlugin, /* new plugin instance */ diff --git a/bacula/src/plugins/fd/example-plugin-fd.c b/bacula/src/plugins/fd/example-plugin-fd.c index afd4b1778a..1b4422cffc 100644 --- a/bacula/src/plugins/fd/example-plugin-fd.c +++ b/bacula/src/plugins/fd/example-plugin-fd.c @@ -65,8 +65,8 @@ static bInfo *binfo = NULL; static pInfo pluginInfo = { sizeof(pluginInfo), - PLUGIN_INTERFACE_VERSION, - PLUGIN_MAGIC, + FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, PLUGIN_AUTHOR, PLUGIN_DATE, @@ -76,7 +76,7 @@ static pInfo pluginInfo = { static pFuncs pluginFuncs = { sizeof(pluginFuncs), - PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ newPlugin, /* new plugin instance */ @@ -167,7 +167,7 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) printf("plugin: StartRestoreJob\n"); break; case bEventEndRestoreJob: - printf("plugin: EndRestoreJob\"); + printf("plugin: EndRestoreJob\n"); break; /* Plugin command e.g. plugin = ::command */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index c60a9802a5..4106cdaddd 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,7 @@ General: 08Mar08 +kes Plugin work -- bring dir up to fd level. kes Start implementation of VTL code kes Fix Win32 build after adding new cats subroutine. 06Mar08