2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation, which is
11 listed in the file LICENSE.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula(R) is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Sample Storage daemon Plugin program
31 * Kern Sibbald, October 2007
36 #include "sd_plugins.h"
42 #define PLUGIN_LICENSE "Bacula AGPLv3"
43 #define PLUGIN_AUTHOR "Kern Sibbald"
44 #define PLUGIN_DATE "November 2011"
45 #define PLUGIN_VERSION "2"
46 #define PLUGIN_DESCRIPTION "Test Storage Daemon Plugin"
48 /* Forward referenced functions */
49 static bRC newPlugin(bpContext *ctx);
50 static bRC freePlugin(bpContext *ctx);
51 static bRC getPluginValue(bpContext *ctx, psdVariable var, void *value);
52 static bRC setPluginValue(bpContext *ctx, psdVariable var, void *value);
53 static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value);
56 /* Pointers to Bacula functions */
57 static bsdFuncs *bfuncs = NULL;
58 static bsdInfo *binfo = NULL;
60 static psdInfo pluginInfo = {
62 SD_PLUGIN_INTERFACE_VERSION,
71 static psdFuncs pluginFuncs = {
73 SD_PLUGIN_INTERFACE_VERSION,
75 /* Entry points into plugin */
76 newPlugin, /* new plugin instance */
77 freePlugin, /* free plugin instance */
84 * loadPlugin() and unloadPlugin() are entry points that are
85 * exported, so Bacula can directly call these two entry points
86 * they are common to all Bacula plugins.
88 * External entry point called by Bacula to "load the plugin
91 loadPlugin(bsdInfo *lbinfo, bsdFuncs *lbfuncs, psdInfo **pinfo, psdFuncs **pfuncs)
93 bfuncs = lbfuncs; /* set Bacula funct pointers */
95 printf("example-plugin-sd: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
96 *pinfo = &pluginInfo; /* return pointer to our info */
97 *pfuncs = &pluginFuncs; /* return pointer to our functions */
98 printf("example-plugin-sd: Loaded\n");
103 * External entry point to unload the plugin
108 printf("example-plugin-sd: Unloaded\n");
113 * The following entry points are accessed through the function
114 * pointers we supplied to Bacula. Each plugin type (dir, fd, sd)
115 * has its own set of entry points that the plugin must define.
118 * Create a new instance of the plugin i.e. allocate our private storage
120 static bRC newPlugin(bpContext *ctx)
123 bfuncs->getBaculaValue(ctx, bsdVarJobId, (void *)&JobId);
124 printf("example-plugin-sd: newPlugin JobId=%d\n", JobId);
125 bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
130 * Free a plugin instance, i.e. release our private storage
132 static bRC freePlugin(bpContext *ctx)
135 bfuncs->getBaculaValue(ctx, bsdVarJobId, (void *)&JobId);
136 printf("example-plugin-sd: freePlugin JobId=%d\n", JobId);
141 * Return some plugin value (none defined)
143 static bRC getPluginValue(bpContext *ctx, psdVariable var, void *value)
145 printf("example-plugin-sd: getPluginValue var=%d\n", var);
150 * Set a plugin value (none defined)
152 static bRC setPluginValue(bpContext *ctx, psdVariable var, void *value)
154 printf("example-plugin-sd: setPluginValue var=%d\n", var);
159 * Handle an event that was generated in Bacula
161 static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value)
164 switch (event->eventType) {
165 case bsdEventJobStart:
166 printf("example-plugin-sd: HandleEvent JobStart :%s:\n", (char *)value);
169 printf("example-plugin-sd: HandleEvent JobEnd\n");
172 bfuncs->getBaculaValue(ctx, bsdVarJobName, (void *)&name);
173 printf("Job Name=%s\n", name);
174 bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
175 bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");