const int dbglvl = 50;
const char *plugin_type = "-fd.so";
-/* External functions */
+/* Function pointers to be set here */
extern int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode);
extern int (*plugin_bclose)(JCR *jcr);
extern ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count);
/* 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,
+static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value);
+static bRC baculaSetValue(bpContext *ctx, bVariable var, void *value);
+static bRC baculaRegisterEvents(bpContext *ctx, ...);
+static bRC 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,
+static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line,
int level, const char *msg);
static int my_plugin_bopen(JCR *jcr, const char *fname, int flags, mode_t mode);
*
* ==============================================================
*/
-static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
+static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value)
{
JCR *jcr = (JCR *)(ctx->bContext);
// Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
if (!value) {
- return 1;
+ return bRC_Error;
}
// Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr);
switch (var) {
case bVarSinceTime:
break;
}
- return 0;
+ return bRC_OK;
}
-static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value)
+static bRC baculaSetValue(bpContext *ctx, bVariable var, void *value)
{
Dmsg1(dbglvl, "bacula: baculaSetValue var=%d\n", var);
- return 0;
+ return bRC_OK;
}
-static bpError baculaRegisterEvents(bpContext *ctx, ...)
+static bRC baculaRegisterEvents(bpContext *ctx, ...)
{
va_list args;
uint32_t event;
Dmsg1(dbglvl, "Plugin wants event=%u\n", event);
}
va_end(args);
- return 0;
+ return bRC_OK;
}
-static bpError baculaJobMsg(bpContext *ctx, const char *file, int line,
+static bRC 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;
+ return bRC_OK;
}
-static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line,
+static bRC 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;
+ return bRC_OK;
}
#ifdef TEST_PROGRAM
int func; /* Function code */
int count; /* read/write count */
char *buf; /* read/write buffer */
+ int status; /* return status */
+ int io_errno; /* errno code */
};
/****************************************************************************
typedef struct s_baculaFuncs {
uint32_t size;
uint32_t version;
- 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,
+ bRC (*registerBaculaEvents)(bpContext *ctx, ...);
+ bRC (*getBaculaValue)(bpContext *ctx, bVariable var, void *value);
+ bRC (*setBaculaValue)(bpContext *ctx, bVariable var, void *value);
+ bRC (*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,
+ bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
int level, const char *msg);
} bFuncs;
typedef struct s_pluginFuncs {
uint32_t size;
uint32_t version;
- 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, void *value);
- bpError (*startPluginBackup)(bpContext *ctx, struct save_pkt *sp);
- bpError (*pluginIO)(bpContext *ctx, struct io_pkt *io);
+ bRC (*newPlugin)(bpContext *ctx);
+ 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, void *value);
+ bRC (*startPluginBackup)(bpContext *ctx, struct save_pkt *sp);
+ bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io);
} pFuncs;
#define plug_func(plugin) ((pFuncs *)(plugin->pfuncs))
extern DLL_IMP_EXP alist *plugin_list;
-/* Universal return code from all functions */
-typedef int32_t bpError;
+/* Universal return codes from all functions */
+typedef enum {
+ bRC_OK = 0, /* OK */
+ bRC_Stop = 1, /* Stop calling plugins */
+ bRC_Error = 2,
+} bRC;
/* Context packet as first argument of all functions */
typedef struct s_bpContext {
} bpContext;
extern "C" {
-typedef bpError (*t_loadPlugin)(void *binfo, void *bfuncs, void **pinfo, void **pfuncs);
-typedef bpError (*t_unloadPlugin)(void);
+typedef bRC (*t_loadPlugin)(void *binfo, void *bfuncs, void **pinfo, void **pfuncs);
+typedef bRC (*t_unloadPlugin)(void);
}
class Plugin {
.c.o:
$(CC) -I${SRCDIR} -I${FDDOR} -DTEST_PROGRAM -c $<
-all: main example-plugin-fd.so
+all: main example-plugin-fd.so bpipe-fd.so
fd-plugins.o: ${FDDIR}/fd-plugins.h ${FDDIR}/fd-plugins.c
$(CC) -I${SRCDIR} -I${FDDIR} -DTEST_PROGRAM -c ${FDDIR}/fd-plugins.c
example-plugin-fd.so: example-plugin-fd.o
$(CC) -shared example-plugin-fd.o -o example-plugin-fd.so
+bpipe-fd.o: bpipe-fd.c ${FDDIR}/fd-plugins.h
+ $(CC) -fPIC -I../.. -I${FDDIR} -c bpipe-fd.c
+
+bpipe-fd.so: bpipe-fd.o
+ $(CC) -shared bpipe-fd.o -o bpipe-fd.so
clean:
rm -f main *.so *.o 1 2 3
--- /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 "fd-plugins.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 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);
+static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp);
+static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
+
+
+/* Pointers to Bacula functions */
+static bFuncs *bfuncs = NULL;
+static bInfo *binfo = NULL;
+
+static pInfo pluginInfo = {
+ sizeof(pluginInfo),
+ PLUGIN_INTERFACE_VERSION,
+ PLUGIN_MAGIC,
+ PLUGIN_LICENSE,
+ PLUGIN_AUTHOR,
+ PLUGIN_DATE,
+ PLUGIN_VERSION,
+ PLUGIN_DESCRIPTION,
+};
+
+static pFuncs pluginFuncs = {
+ sizeof(pluginFuncs),
+ PLUGIN_INTERFACE_VERSION,
+
+ /* Entry points into plugin */
+ newPlugin, /* new plugin instance */
+ freePlugin, /* free plugin instance */
+ getPluginValue,
+ setPluginValue,
+ handlePluginEvent,
+ startPluginBackup,
+ pluginIO
+};
+
+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->version);
+
+ *pinfo = &pluginInfo; /* return pointer to our info */
+ *pfuncs = &pluginFuncs; /* return pointer to our functions */
+
+ return bRC_OK;
+}
+
+bRC unloadPlugin()
+{
+ printf("plugin: Unloaded\n");
+ return bRC_OK;
+}
+
+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 bRC_OK;
+}
+
+static bRC freePlugin(bpContext *ctx)
+{
+ int JobId = 0;
+ bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
+// printf("plugin: freePlugin JobId=%d\n", JobId);
+ return bRC_OK;
+}
+
+static bRC getPluginValue(bpContext *ctx, pVariable var, void *value)
+{
+// printf("plugin: getPluginValue var=%d\n", var);
+ return bRC_OK;
+}
+
+static bRC setPluginValue(bpContext *ctx, pVariable var, void *value)
+{
+// printf("plugin: setPluginValue var=%d\n", var);
+ return bRC_OK;
+}
+
+static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
+{
+ char *name;
+
+ switch (event->eventType) {
+ case bEventJobStart:
+ printf("plugin: JobStart=%s\n", (char *)value);
+ break;
+ case bEventJobEnd:
+ printf("plugin: JobEnd\n");
+ break;
+ case bEventBackupStart:
+ printf("plugin: BackupStart\n");
+ break;
+ case bEventBackupEnd:
+ printf("plugin: BackupEnd\n");
+ break;
+ case bEventLevel:
+ printf("plugin: JobLevel=%c %d\n", (int)value, (int)value);
+ break;
+ case bEventSince:
+ printf("plugin: since=%d\n", (int)value);
+ break;
+
+ /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
+ case bEventPluginCommand:
+ printf("plugin: command=%s\n", (char *)value);
+ break;
+
+ default:
+ printf("plugin: unknown event=%d\n", event->eventType);
+ }
+ bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
+// printf("FD Name=%s\n", name);
+// bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
+// bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
+ return bRC_OK;
+}
+
+static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp)
+{
+ return bRC_OK;
+}
+
+/*
+ * Do actual I/O
+ */
+static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
+{
+ io->status = 0;
+ io->io_errno = 0;
+ switch(io->func) {
+ case IO_OPEN:
+ printf("plugin: IO_OPEN\n");
+ break;
+ case IO_READ:
+ printf("plugin: IO_READ buf=%p len=%d\n", io->buf, io->count);
+ break;
+ case IO_WRITE:
+ printf("plugin: IO_WRITE buf=%p len=%d\n", io->buf, io->count);
+ break;
+ case IO_CLOSE:
+ printf("plugin: IO_CLOSE\n");
+ break;
+ }
+ return bRC_OK;
+}
+
+#ifdef __cplusplus
+}
+#endif
#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, void *value);
+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);
+static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp);
+static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
/* Pointers to Bacula functions */
freePlugin, /* free plugin instance */
getPluginValue,
setPluginValue,
- handlePluginEvent
+ handlePluginEvent,
+ startPluginBackup,
+ pluginIO
};
-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;
*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, void *value)
+static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
{
char *name;
+
switch (event->eventType) {
case bEventJobStart:
printf("plugin: JobStart=%s\n", (char *)value);
case bEventBackupEnd:
printf("plugin: BackupEnd\n");
break;
- case bEventPluginCommand:
- printf("plugin: command=%s\n", (char *)value);
- break;
case bEventLevel:
printf("plugin: JobLevel=%c %d\n", (int)value, (int)value);
break;
case bEventSince:
printf("plugin: since=%d\n", (int)value);
break;
+
+ /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
+ case bEventPluginCommand:
+ printf("plugin: command=%s\n", (char *)value);
+ break;
+
default:
printf("plugin: unknown event=%d\n", event->eventType);
}
// printf("FD 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;
+}
+
+static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp)
+{
+ return bRC_OK;
+}
+
+/*
+ * Do actual I/O
+ */
+static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
+{
+ io->status = 0;
+ io->io_errno = 0;
+ switch(io->func) {
+ case IO_OPEN:
+ printf("plugin: IO_OPEN\n");
+ break;
+ case IO_READ:
+ printf("plugin: IO_READ buf=%p len=%d\n", io->buf, io->count);
+ break;
+ case IO_WRITE:
+ printf("plugin: IO_WRITE buf=%p len=%d\n", io->buf, io->count);
+ break;
+ case IO_CLOSE:
+ printf("plugin: IO_CLOSE\n");
+ break;
+ }
+ return bRC_OK;
}
#ifdef __cplusplus