2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
17 * Sample Storage daemon Plugin program
19 * Kern Sibbald, October 2007
29 #define PLUGIN_LICENSE "Bacula AGPLv3"
30 #define PLUGIN_AUTHOR "Kern Sibbald"
31 #define PLUGIN_DATE "November 2011"
32 #define PLUGIN_VERSION "2"
33 #define PLUGIN_DESCRIPTION "Test Storage Daemon Plugin"
35 /* Forward referenced functions */
36 static bRC newPlugin(bpContext *ctx);
37 static bRC freePlugin(bpContext *ctx);
38 static bRC getPluginValue(bpContext *ctx, psdVariable var, void *value);
39 static bRC setPluginValue(bpContext *ctx, psdVariable var, void *value);
40 static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value);
43 /* Pointers to Bacula functions */
44 static bsdFuncs *bfuncs = NULL;
45 static bsdInfo *binfo = NULL;
47 static psdInfo pluginInfo = {
49 SD_PLUGIN_INTERFACE_VERSION,
58 static psdFuncs pluginFuncs = {
60 SD_PLUGIN_INTERFACE_VERSION,
62 /* Entry points into plugin */
63 newPlugin, /* new plugin instance */
64 freePlugin, /* free plugin instance */
71 * loadPlugin() and unloadPlugin() are entry points that are
72 * exported, so Bacula can directly call these two entry points
73 * they are common to all Bacula plugins.
75 * External entry point called by Bacula to "load the plugin
78 loadPlugin(bsdInfo *lbinfo, bsdFuncs *lbfuncs, psdInfo **pinfo, psdFuncs **pfuncs)
80 bfuncs = lbfuncs; /* set Bacula funct pointers */
82 printf("example-plugin-sd: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
83 *pinfo = &pluginInfo; /* return pointer to our info */
84 *pfuncs = &pluginFuncs; /* return pointer to our functions */
85 printf("example-plugin-sd: Loaded\n");
90 * External entry point to unload the plugin
95 printf("example-plugin-sd: Unloaded\n");
100 * The following entry points are accessed through the function
101 * pointers we supplied to Bacula. Each plugin type (dir, fd, sd)
102 * has its own set of entry points that the plugin must define.
105 * Create a new instance of the plugin i.e. allocate our private storage
107 static bRC newPlugin(bpContext *ctx)
110 bfuncs->getBaculaValue(ctx, bsdVarJobId, (void *)&JobId);
111 printf("example-plugin-sd: newPlugin JobId=%d\n", JobId);
112 bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
117 * Free a plugin instance, i.e. release our private storage
119 static bRC freePlugin(bpContext *ctx)
122 bfuncs->getBaculaValue(ctx, bsdVarJobId, (void *)&JobId);
123 printf("example-plugin-sd: freePlugin JobId=%d\n", JobId);
128 * Return some plugin value (none defined)
130 static bRC getPluginValue(bpContext *ctx, psdVariable var, void *value)
132 printf("example-plugin-sd: getPluginValue var=%d\n", var);
137 * Set a plugin value (none defined)
139 static bRC setPluginValue(bpContext *ctx, psdVariable var, void *value)
141 printf("example-plugin-sd: setPluginValue var=%d\n", var);
146 * Handle an event that was generated in Bacula
148 static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value)
151 switch (event->eventType) {
152 case bsdEventJobStart:
153 printf("example-plugin-sd: HandleEvent JobStart :%s:\n", (char *)value);
156 printf("example-plugin-sd: HandleEvent JobEnd\n");
159 bfuncs->getBaculaValue(ctx, bsdVarJobName, (void *)&name);
160 printf("Job Name=%s\n", name);
161 bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
162 bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");