.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:
--- /dev/null
+/*
+ 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 <stdio.h>
+#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
/*
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.
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 = {
baculaRegisterEvents,
baculaGetValue,
baculaSetValue,
- NULL,
- NULL,
+ baculaJobMsg,
+ baculaDebugMsg
};
/* 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);
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;
}
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;
+}
+++ /dev/null
-/*
- 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 <stdio.h>
-#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
/* 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 {
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;