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"
44 #define PLUGIN_LICENSE "GPL"
45 #define PLUGIN_AUTHOR "Kern Sibbald"
46 #define PLUGIN_DATE "January 2008"
47 #define PLUGIN_VERSION "1"
48 #define PLUGIN_DESCRIPTION "Test File Daemon Plugin"
50 /* Forward referenced functions */
51 static bRC newPlugin(bpContext *ctx);
52 static bRC freePlugin(bpContext *ctx);
53 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value);
54 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value);
55 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value);
56 static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp);
57 static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
60 /* Pointers to Bacula functions */
61 static bFuncs *bfuncs = NULL;
62 static bInfo *binfo = NULL;
64 static pInfo pluginInfo = {
66 PLUGIN_INTERFACE_VERSION,
75 static pFuncs pluginFuncs = {
77 PLUGIN_INTERFACE_VERSION,
79 /* Entry points into plugin */
80 newPlugin, /* new plugin instance */
81 freePlugin, /* free plugin instance */
93 bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
95 bfuncs = lbfuncs; /* set Bacula funct pointers */
97 printf("bpipe-fd: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
99 *pinfo = &pluginInfo; /* return pointer to our info */
100 *pfuncs = &pluginFuncs; /* return pointer to our functions */
107 printf("bpipe-fd: Unloaded\n");
111 static bRC newPlugin(bpContext *ctx)
113 struct plugin_ctx *p_ctx = (struct plugin_ctx *)malloc(sizeof(struct plugin_ctx));
116 ctx->pContext = (void *)p_ctx; /* set our context pointer */
120 static bRC freePlugin(bpContext *ctx)
122 struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext;
127 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value)
132 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value)
137 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
141 switch (event->eventType) {
143 printf("bpipe-fd: JobStart=%s\n", (char *)value);
146 printf("bpipe-fd: JobEnd\n");
148 case bEventBackupStart:
149 printf("bpipe-fd: BackupStart\n");
151 case bEventBackupEnd:
152 printf("bpipe-fd: BackupEnd\n");
155 printf("bpipe-fd: JobLevel=%c %d\n", (int)value, (int)value);
158 printf("bpipe-fd: since=%d\n", (int)value);
161 /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
162 case bEventPluginCommand:
163 printf("bpipe-fd: command=%s\n", (char *)value);
167 printf("bpipe-fd: unknown event=%d\n", event->eventType);
169 bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
170 // printf("FD Name=%s\n", name);
171 // bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
172 // bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
176 static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp)
178 static char *fname = (char *)"/BPIPE/test.txt";
179 time_t now = time(NULL);
181 sp->statp.st_mode = 0700;
182 sp->statp.st_ctime = now;
183 sp->statp.st_mtime = now;
184 sp->statp.st_atime = now;
185 sp->statp.st_size = 100;
186 sp->statp.st_blksize = 4096;
187 sp->statp.st_blocks = 1;
188 printf("bpipe-fd: startPluginBackup\n");
195 static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
197 struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext;
204 printf("bpipe-fd: IO_OPEN\n");
207 printf("bpipe-fd: IO_READ buf=%p len=%d\n", io->buf, io->count);
208 if (p_ctx->record == 0) {
209 strcpy(io->buf, "This is a test string.\n");
210 io->status = strlen(io->buf);
217 printf("bpipe-fd: IO_WRITE buf=%p len=%d\n", io->buf, io->count);
220 printf("bpipe-fd: IO_CLOSE\n");