2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2010 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® 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 Plugin program
31 * Kern Sibbald, October 2007
35 #include "dir_plugins.h"
41 #define PLUGIN_LICENSE "Bacula AGPLv3"
42 #define PLUGIN_AUTHOR "Kern Sibbald"
43 #define PLUGIN_DATE "January 2008"
44 #define PLUGIN_VERSION "1"
45 #define PLUGIN_DESCRIPTION "Test Director Daemon Plugin"
47 /* Forward referenced functions */
48 static bRC newPlugin(bpContext *ctx);
49 static bRC freePlugin(bpContext *ctx);
50 static bRC getPluginValue(bpContext *ctx, pDirVariable var, void *value);
51 static bRC setPluginValue(bpContext *ctx, pDirVariable var, void *value);
52 static bRC handlePluginEvent(bpContext *ctx, bDirEvent *event, void *value);
55 /* Pointers to Bacula functions */
56 static bDirFuncs *bfuncs = NULL;
57 static bDirInfo *binfo = NULL;
59 static pDirInfo pluginInfo = {
61 DIR_PLUGIN_INTERFACE_VERSION,
70 static pDirFuncs pluginFuncs = {
72 DIR_PLUGIN_INTERFACE_VERSION,
74 /* Entry points into plugin */
75 newPlugin, /* new plugin instance */
76 freePlugin, /* free plugin instance */
82 bRC loadPlugin(bDirInfo *lbinfo, bDirFuncs *lbfuncs, pDirInfo **pinfo, pDirFuncs **pfuncs)
84 bfuncs = lbfuncs; /* set Bacula funct pointers */
86 printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
88 *pinfo = &pluginInfo; /* return pointer to our info */
89 *pfuncs = &pluginFuncs; /* return pointer to our functions */
96 printf("plugin: Unloaded\n");
100 static bRC newPlugin(bpContext *ctx)
103 bfuncs->getBaculaValue(ctx, bDirVarJobId, (void *)&JobId);
104 printf("plugin: newPlugin JobId=%d\n", JobId);
105 bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
109 static bRC freePlugin(bpContext *ctx)
112 bfuncs->getBaculaValue(ctx, bDirVarJobId, (void *)&JobId);
113 printf("plugin: freePlugin JobId=%d\n", JobId);
117 static bRC getPluginValue(bpContext *ctx, pDirVariable var, void *value)
119 printf("plugin: getPluginValue var=%d\n", var);
123 static bRC setPluginValue(bpContext *ctx, pDirVariable var, void *value)
125 printf("plugin: setPluginValue var=%d\n", var);
129 static bRC handlePluginEvent(bpContext *ctx, bDirEvent *event, void *value)
133 switch (event->eventType) {
134 case bDirEventJobStart:
135 printf("plugin: HandleEvent JobStart\n");
137 case bDirEventJobEnd:
138 printf("plugin: HandleEvent JobEnd\n");
139 bfuncs->getBaculaValue(ctx, bDirVarJob, (void *)&name);
140 printf("plugin: bDirVarJob=%s\n", name);
141 bfuncs->getBaculaValue(ctx, bDirVarJobId, (void *)&val);
142 printf("plugin: bDirVarJobId=%d\n", val);
143 bfuncs->getBaculaValue(ctx, bDirVarType, (void *)&val);
144 printf("plugin: bDirVarType=%c\n", val);
145 bfuncs->getBaculaValue(ctx, bDirVarLevel, (void *)&val);
146 printf("plugin: bDirVarLevel=%c\n", val);
147 bfuncs->getBaculaValue(ctx, bDirVarClient, (void *)&name);
148 printf("plugin: bDirVarClient=%s\n", name);
149 bfuncs->getBaculaValue(ctx, bDirVarCatalog, (void *)&name);
150 printf("plugin: bDirVarCatalog=%s\n", name);
151 bfuncs->getBaculaValue(ctx, bDirVarPool, (void *)&name);
152 printf("plugin: bDirVarPool=%s\n", name);
153 bfuncs->getBaculaValue(ctx, bDirVarStorage, (void *)&name);
154 printf("plugin: bDirVarStorage=%s\n", name);
155 bfuncs->getBaculaValue(ctx, bDirVarJobErrors, (void *)&val);
156 printf("plugin: bDirVarJobErrors=%d\n", val);
157 bfuncs->getBaculaValue(ctx, bDirVarJobFiles, (void *)&val);
158 printf("plugin: bDirVarJobFiles=%d\n", val);
159 bfuncs->getBaculaValue(ctx, bDirVarNumVols, (void *)&val);
160 printf("plugin: bDirVarNumVols=%d\n", val);
164 bfuncs->getBaculaValue(ctx, bDirVarJobName, (void *)&name);
165 printf("Job Name=%s\n", name);
166 bfuncs->JobMessage(ctx, __FILE__, __LINE__, M_INFO, 0, "JobMesssage message");
167 bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");