2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 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 two of the GNU 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 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 John Walker.
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 "fd-plugins.h"
41 #define PLUGIN_LICENSE "GPL"
42 #define PLUGIN_AUTHOR "Kern Sibbald"
43 #define PLUGIN_DATE "January 2008"
44 #define PLUGIN_VERSION "1"
45 #define PLUGIN_DESCRIPTION "Test File Daemon Plugin"
47 /* Forward referenced functions */
48 static bRC newPlugin(bpContext *ctx);
49 static bRC freePlugin(bpContext *ctx);
50 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value);
51 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value);
52 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value);
53 static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp);
54 static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
57 /* Pointers to Bacula functions */
58 static bFuncs *bfuncs = NULL;
59 static bInfo *binfo = NULL;
61 static pInfo pluginInfo = {
63 PLUGIN_INTERFACE_VERSION,
72 static pFuncs pluginFuncs = {
74 PLUGIN_INTERFACE_VERSION,
76 /* Entry points into plugin */
77 newPlugin, /* new plugin instance */
78 freePlugin, /* free plugin instance */
86 bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
88 bfuncs = lbfuncs; /* set Bacula funct pointers */
90 printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
92 *pinfo = &pluginInfo; /* return pointer to our info */
93 *pfuncs = &pluginFuncs; /* return pointer to our functions */
100 printf("plugin: Unloaded\n");
104 static bRC newPlugin(bpContext *ctx)
107 bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
108 // printf("plugin: newPlugin JobId=%d\n", JobId);
109 bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
113 static bRC freePlugin(bpContext *ctx)
116 bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
117 // printf("plugin: freePlugin JobId=%d\n", JobId);
121 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value)
123 // printf("plugin: getPluginValue var=%d\n", var);
127 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value)
129 // printf("plugin: setPluginValue var=%d\n", var);
133 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
137 switch (event->eventType) {
139 printf("plugin: JobStart=%s\n", (char *)value);
142 printf("plugin: JobEnd\n");
144 case bEventBackupStart:
145 printf("plugin: BackupStart\n");
147 case bEventBackupEnd:
148 printf("plugin: BackupEnd\n");
151 printf("plugin: JobLevel=%c %d\n", (int)value, (int)value);
154 printf("plugin: since=%d\n", (int)value);
156 case bEventRestoreStart:
157 printf("bpipe-fd: RestoreStart\n");
159 case bEventRestoreEnd:
160 printf("bpipe-fd: RestoreEnd\n");
163 /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
164 case bEventPluginCommand:
165 printf("plugin: command=%s\n", (char *)value);
169 printf("plugin: unknown event=%d\n", event->eventType);
171 bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
172 // printf("FD Name=%s\n", name);
173 // bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
174 // bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
178 static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp)
186 static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
192 printf("plugin: IO_OPEN\n");
195 printf("plugin: IO_READ buf=%p len=%d\n", io->buf, io->count);
198 printf("plugin: IO_WRITE buf=%p len=%d\n", io->buf, io->count);
201 printf("plugin: IO_CLOSE\n");