all: main example-plugin-fd.so
-main: main.o plugin-fd.h
+main: main.o fd-plugins.h
$(CC) -L../../lib main.o -o main -lbac -lpthread -lssl -l crypto -ldl
-example-plugin-fd.o: example-plugin-fd.c plugin-fd.h
+example-plugin-fd.o: example-plugin-fd.c fd-plugins.h
$(CC) -fPIC -I../.. -c example-plugin-fd.c
example-plugin-fd.so: example-plugin-fd.o
*
*/
#include <stdio.h>
-#include "plugin-fd.h"
+#include "fd-plugins.h"
#ifdef __cplusplus
extern "C" {
--- /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.
+*/
+/*
+ * Interface definition for Bacula Plugins
+ *
+ * Kern Sibbald, October 2007
+ *
+ */
+
+#ifndef __PLUGIN_FD_H
+#define __PLUGIN_FD_H
+
+#include <sys/types.h>
+#ifndef __CONFIG_H
+#define __CONFIG_H
+#include "config.h"
+#endif
+#include "bc_types.h"
+#include "lib/plugin.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;
+
+
+/****************************************************************************
+ * *
+ * 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 /* __PLUGIN_FD_H */
* Kern Sibbald, October 2007
*/
#include "bacula.h"
+#include "jcr.h"
#include "lib/plugin.h"
-#include "plugin-fd.h"
+#include "fd-plugins.h"
const char *plugin_type = "-fd.so";
static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line,
int level, const char *msg);
+void load_fd_plugins(const char *plugin_dir);
+void new_plugins(JCR *jcr);
+void free_plugins(JCR *jcr);
+void plugin_event(JCR *jcr, bEventType event);
+
+
/* Bacula info */
static bInfo binfo = {
sizeof(bFuncs),
};
-
-
int main(int argc, char *argv[])
{
char plugin_dir[1000];
- bpContext ctx;
- bEvent event;
- Plugin *plugin;
+ JCR mjcr1, mjcr2;
+ JCR *jcr1 = &mjcr1;
+ JCR *jcr2 = &mjcr2;
- plugin_list = New(alist(10, not_owned_by_alist));
-
- ctx.bContext = NULL;
- ctx.pContext = NULL;
getcwd(plugin_dir, sizeof(plugin_dir)-1);
+ load_fd_plugins(plugin_dir);
- load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type);
+ jcr1->JobId = 1;
+ new_plugins(jcr1);
- foreach_alist(plugin, plugin_list) {
- printf("bacula: plugin_size=%d plugin_version=%d\n",
- plug_func(plugin)->size, plug_func(plugin)->interface);
- printf("License: %s\nAuthor: %s\nDate: %s\nVersion: %s\nDescription: %s\n",
- 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 */
- plug_func(plugin)->newPlugin(&ctx);
- 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 = 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);
- }
+ jcr2->JobId = 2;
+ new_plugins(jcr2);
+
+ plugin_event(jcr1, bEventJobStart);
+ plugin_event(jcr1, bEventJobEnd);
+ plugin_event(jcr2, bEventJobStart);
+ free_plugins(jcr1);
+ plugin_event(jcr2, bEventJobEnd);
+ free_plugins(jcr2);
unload_plugins();
return 0;
}
+void plugin_event(JCR *jcr, bEventType eventType)
+{
+ bEvent event;
+ Plugin *plugin;
+ int i = 0;
+
+ bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
+ event.eventType = eventType;
+ foreach_alist(plugin, plugin_list) {
+ plug_func(plugin)->handlePluginEvent(&plugin_ctx[i++], &event);
+ }
+}
+
+void load_fd_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;
+
+ int num = plugin_list->size();
+
+ if (num == 0) {
+ return;
+ }
+
+ jcr->plugin_ctx = (void *)malloc(sizeof(bpContext) * num);
+
+ bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
+ 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;
+
+ bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
+ foreach_alist(plugin, plugin_list) {
+ /* Free the plugin instance */
+ plug_func(plugin)->freePlugin(&plugin_ctx[i++]);
+ }
+ free(plugin_ctx);
+ jcr->plugin_ctx = NULL;
+}
+
+
static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
{
printf("bacula: baculaGetValue var=%d\n", var);
}
switch (var) {
case bVarJobId:
- *((int *)value) = 100;
+ *((int *)value) = ((JCR *)ctx)->JobId;
break;
case bVarFDName:
*((char **)value) = "FD Name";
+++ /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.
-*/
-/*
- * Interface definition for Bacula Plugins
- *
- * Kern Sibbald, October 2007
- *
- */
-
-#ifndef __PLUGIN_FD_H
-#define __PLUGIN_FD_H
-
-#include <sys/types.h>
-#ifndef __CONFIG_H
-#define __CONFIG_H
-#include "config.h"
-#endif
-#include "bc_types.h"
-#include "lib/plugin.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;
-
-
-/****************************************************************************
- * *
- * 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 /* __PLUGIN_FD_H */