2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2007-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Sample Storage daemon Plugin program
23 * Kern Sibbald, October 2007
26 #include "bacula.h" /* General Bacula headers */
27 #include "stored.h" /* Pull in storage daemon headers */
33 #define PLUGIN_LICENSE "AGPLv3"
34 #define PLUGIN_AUTHOR "Kern Sibbald"
35 #define PLUGIN_DATE "November 2011"
36 #define PLUGIN_VERSION "2"
37 #define PLUGIN_DESCRIPTION "Test Storage Daemon Plugin"
39 /* Forward referenced functions */
40 static bRC newPlugin(bpContext *ctx);
41 static bRC freePlugin(bpContext *ctx);
42 static bRC getPluginValue(bpContext *ctx, psdVariable var, void *value);
43 static bRC setPluginValue(bpContext *ctx, psdVariable var, void *value);
44 static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value);
45 static bRC handleGlobalPluginEvent(bsdEvent *event, void *value);
48 /* Pointers to Bacula functions */
49 static bsdFuncs *bfuncs = NULL;
50 static bsdInfo *binfo = NULL;
52 static psdInfo pluginInfo = {
54 SD_PLUGIN_INTERFACE_VERSION,
63 static psdFuncs pluginFuncs = {
65 SD_PLUGIN_INTERFACE_VERSION,
67 /* Entry points into plugin */
68 newPlugin, /* new plugin instance */
69 freePlugin, /* free plugin instance */
73 handleGlobalPluginEvent
77 * loadPlugin() and unloadPlugin() are entry points that are
78 * exported, so Bacula can directly call these two entry points
79 * they are common to all Bacula plugins.
81 * External entry point called by Bacula to "load the plugin
84 loadPlugin(bsdInfo *lbinfo, bsdFuncs *lbfuncs, psdInfo **pinfo, psdFuncs **pfuncs)
86 bfuncs = lbfuncs; /* set Bacula funct pointers */
88 printf("example-plugin-sd: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
89 *pinfo = &pluginInfo; /* return pointer to our info */
90 *pfuncs = &pluginFuncs; /* return pointer to our functions */
91 printf("example-plugin-sd: Loaded\n");
96 * External entry point to unload the plugin
101 printf("example-plugin-sd: Unloaded\n");
106 * The following entry points are accessed through the function
107 * pointers we supplied to Bacula. Each plugin type (dir, fd, sd)
108 * has its own set of entry points that the plugin must define.
111 * Create a new instance of the plugin i.e. allocate our private storage
113 static bRC newPlugin(bpContext *ctx)
116 bfuncs->getBaculaValue(ctx, bsdVarJobId, (void *)&JobId);
117 printf("example-plugin-sd: newPlugin JobId=%d\n", JobId);
118 bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
123 * Free a plugin instance, i.e. release our private storage
125 static bRC freePlugin(bpContext *ctx)
128 bfuncs->getBaculaValue(ctx, bsdVarJobId, (void *)&JobId);
129 printf("example-plugin-sd: freePlugin JobId=%d\n", JobId);
134 * Return some plugin value (none defined)
136 static bRC getPluginValue(bpContext *ctx, psdVariable var, void *value)
138 printf("example-plugin-sd: getPluginValue var=%d\n", var);
143 * Set a plugin value (none defined)
145 static bRC setPluginValue(bpContext *ctx, psdVariable var, void *value)
147 printf("example-plugin-sd: setPluginValue var=%d\n", var);
152 * Handle an event that was generated in Bacula
154 static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value)
157 switch (event->eventType) {
158 case bsdEventJobStart:
159 printf("example-plugin-sd: HandleEvent JobStart :%s:\n", (char *)value);
162 printf("example-plugin-sd: HandleEvent JobEnd\n");
165 bfuncs->getBaculaValue(ctx, bsdVarJobName, (void *)&name);
166 printf("Job Name=%s\n", name);
167 bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
168 bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
173 * Handle a Global event -- no context
175 static bRC handleGlobalPluginEvent(bsdEvent *event, void *value)