From: Kern Sibbald Date: Wed, 2 Jan 2008 14:34:52 +0000 (+0000) Subject: A little work on FD plugin X-Git-Tag: Release-7.0.0~5217 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b5de1ab7e41c398b670f93ab6d6f002e4d2e4f1e;p=bacula%2Fbacula A little work on FD plugin git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6179 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/plugins/fd/Makefile b/bacula/src/plugins/fd/Makefile index 96776447bf..6d6e68830a 100644 --- a/bacula/src/plugins/fd/Makefile +++ b/bacula/src/plugins/fd/Makefile @@ -9,20 +9,16 @@ CC = g++ -g -O0 -Wall .c.o: $(CC) -I../.. -DTEST_PROGRAM -c $< -all: main plugin-fd.so +all: main example-plugin-fd.so main: main.o plugin-fd.h $(CC) -L../../lib main.o -o main -lbac -lpthread -lssl -l crypto -ldl -plugin-fd.o: plugin-fd.c plugin-fd.h - $(CC) -fPIC -I../.. -c plugin-fd.c +example-plugin-fd.o: example-plugin-fd.c plugin-fd.h + $(CC) -fPIC -I../.. -c example-plugin-fd.c -plugin.o: plugin.c plugin.h - $(CC) -fPIC -I../.. -c plugin.c - - -plugin-fd.so: plugin-fd.o - $(CC) -shared plugin-fd.o -o plugin-fd.so +example-plugin-fd.so: example-plugin-fd.o + $(CC) -shared example-plugin-fd.o -o example-plugin-fd.so clean: diff --git a/bacula/src/plugins/fd/example-plugin-fd.c b/bacula/src/plugins/fd/example-plugin-fd.c new file mode 100644 index 0000000000..fd5e6326c0 --- /dev/null +++ b/bacula/src/plugins/fd/example-plugin-fd.c @@ -0,0 +1,140 @@ +/* + 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. +*/ +/* + * Sample Plugin program + * + * Kern Sibbald, October 2007 + * + */ +#include +#include "plugin-fd.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PLUGIN_LICENSE "GPL" +#define PLUGIN_AUTHOR "Kern Sibbald" +#define PLUGIN_DATE "January 2008" +#define PLUGIN_VERSION "1" +#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); + + +/* Pointers to Bacula functions */ +static bFuncs *bfuncs = NULL; +static bInfo *binfo = NULL; + +static pInfo pluginInfo = { + sizeof(pluginInfo), + PLUGIN_INTERFACE, + PLUGIN_MAGIC, + PLUGIN_LICENSE, + PLUGIN_AUTHOR, + PLUGIN_DATE, + PLUGIN_VERSION, + PLUGIN_DESCRIPTION, +}; + +static pFuncs pluginFuncs = { + sizeof(pluginFuncs), + PLUGIN_INTERFACE, + + /* Entry points into plugin */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, + setPluginValue, + handlePluginEvent +}; + +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; +} + +bpError unloadPlugin() +{ + printf("plugin: Unloaded\n"); + return 0; +} + +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; +} + +static bpError freePlugin(bpContext *ctx) +{ + int JobId = 0; + bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId); + printf("plugin: freePlugin JobId=%d\n", JobId); + return 0; +} + +static bpError getPluginValue(bpContext *ctx, pVariable var, void *value) +{ + printf("plugin: getPluginValue var=%d\n", var); + return 0; +} + +static bpError setPluginValue(bpContext *ctx, pVariable var, void *value) +{ + printf("plugin: setPluginValue var=%d\n", var); + return 0; +} + +static bpError handlePluginEvent(bpContext *ctx, bEvent *event) +{ + char *name; + printf("plugin: HandleEvent Event=%d\n", event->eventType); + bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name); + printf("FD Name=%s\n", name); + return 0; +} + +#ifdef __cplusplus +} +#endif diff --git a/bacula/src/plugins/fd/main.c b/bacula/src/plugins/fd/main.c index 3333a912aa..98c8ef7898 100644 --- a/bacula/src/plugins/fd/main.c +++ b/bacula/src/plugins/fd/main.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2007-2007 Free Software Foundation Europe e.V. + 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. @@ -43,6 +43,10 @@ const char *plugin_type = "-fd.so"; 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 = { @@ -57,8 +61,8 @@ static bFuncs bfuncs = { baculaRegisterEvents, baculaGetValue, baculaSetValue, - NULL, - NULL, + baculaJobMsg, + baculaDebugMsg }; @@ -89,14 +93,18 @@ int main(int argc, char *argv[]) /* Start a new instance of the plugin */ plug_func(plugin)->newPlugin(&ctx); - event.eventType = bEventNewVolume; + event.eventType = bEventJobStart; + plug_func(plugin)->handlePluginEvent(&ctx, &event); + event.eventType = bEventJobEnd; plug_func(plugin)->handlePluginEvent(&ctx, &event); /* Free the plugin instance */ plug_func(plugin)->freePlugin(&ctx); /* Start a new instance of the plugin */ plug_func(plugin)->newPlugin(&ctx); - event.eventType = bEventNewVolume; + event.eventType = bEventJobStart; + plug_func(plugin)->handlePluginEvent(&ctx, &event); + event.eventType = bEventJobEnd; plug_func(plugin)->handlePluginEvent(&ctx, &event); /* Free the plugin instance */ plug_func(plugin)->freePlugin(&ctx); @@ -113,8 +121,23 @@ int main(int argc, char *argv[]) static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value) { printf("bacula: baculaGetValue var=%d\n", var); - if (value) { + if (!value) { + return 1; + } + switch (var) { + case bVarJobId: *((int *)value) = 100; + break; + case bVarFDName: + *((char **)value) = "FD Name"; + break; + case bVarLevel: + case bVarType: + case bVarClient: + case bVarJobName: + case bVarJobStatus: + case bVarSinceTime: + break; } return 0; } @@ -137,3 +160,19 @@ static bpError baculaRegisterEvents(bpContext *ctx, ...) va_end(args); return 0; } + +static bpError baculaJobMsg(bpContext *ctx, const char *file, int line, + int type, time_t mtime, const char *msg) +{ + printf("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) +{ + printf("Debug message: %s:%d level=%d msg=%s\n", + file, line, level, msg); + return 0; +} diff --git a/bacula/src/plugins/fd/plugin-fd.c b/bacula/src/plugins/fd/plugin-fd.c deleted file mode 100644 index a00d384b1c..0000000000 --- a/bacula/src/plugins/fd/plugin-fd.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2007-2007 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. -*/ -/* - * Sample Plugin program - * - * Kern Sibbald, October 2007 - * - */ -#include -#include "plugin-fd.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PLUGIN_LICENSE "GPL" -#define PLUGIN_AUTHOR "Kern Sibbald" -#define PLUGIN_DATE "November 2007" -#define PLUGIN_VERSION "1" -#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); - - -/* Pointers to Bacula functions */ -static bFuncs *bfuncs = NULL; -static bInfo *binfo = NULL; - -static pInfo pluginInfo = { - sizeof(pluginInfo), - PLUGIN_INTERFACE, - PLUGIN_MAGIC, - PLUGIN_LICENSE, - PLUGIN_AUTHOR, - PLUGIN_DATE, - PLUGIN_VERSION, - PLUGIN_DESCRIPTION, -}; - -static pFuncs pluginFuncs = { - sizeof(pluginFuncs), - PLUGIN_INTERFACE, - - /* Entry points into plugin */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, - setPluginValue, - handlePluginEvent -}; - -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; -} - -bpError unloadPlugin() -{ - printf("plugin: Unloaded\n"); - return 0; -} - -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; -} - -static bpError freePlugin(bpContext *ctx) -{ - int JobId = 0; - bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId); - printf("plugin: freePlugin JobId=%d\n", JobId); - return 0; -} - -static bpError getPluginValue(bpContext *ctx, pVariable var, void *value) -{ - printf("plugin: getPluginValue var=%d\n", var); - return 0; -} - -static bpError setPluginValue(bpContext *ctx, pVariable var, void *value) -{ - printf("plugin: setPluginValue var=%d\n", var); - return 0; -} - -static bpError handlePluginEvent(bpContext *ctx, bEvent *event) -{ - printf("plugin: HandleEvent Event=%d\n", event->eventType); - return 0; -} - -#ifdef __cplusplus -} -#endif diff --git a/bacula/src/plugins/fd/plugin-fd.h b/bacula/src/plugins/fd/plugin-fd.h index 2f1010bae5..21167c2eb3 100644 --- a/bacula/src/plugins/fd/plugin-fd.h +++ b/bacula/src/plugins/fd/plugin-fd.h @@ -56,17 +56,19 @@ extern "C" { /* Bacula Variable Ids */ typedef enum { - bVarJobId = 1 + bVarJobId = 1, + bVarFDName = 2, + bVarLevel = 3, + bVarType = 4, + bVarClient = 5, + bVarJobName = 6, + bVarJobStatus = 7, + bVarSinceTime = 8 } bVariable; typedef enum { bEventJobStart = 1, - bEventJobInit = 2, - bEventJobRun = 3, - bEventJobEnd = 4, - bEventNewVolume = 5, - bEventVolumePurged = 6, - bEventReload = 7 + bEventJobEnd = 2, } bEventType; typedef struct s_bEvent { @@ -85,8 +87,10 @@ typedef struct s_baculaFuncs { 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); - bpError (*freeBaculaMem)(bpContext *ctx, char *addr); + 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;