3 Copyright (C) 2007-2008 Kern Sibbald
5 You may freely use this code to create your own plugin provided
6 it is to write a plugin for Bacula licensed under GPLv2
7 (as Bacula is), and in that case, you may also remove
8 the above Copyright and this notice as well as modify
13 #include "fd_plugins.h"
19 #define PLUGIN_LICENSE "GPL"
20 #define PLUGIN_AUTHOR "Your name"
21 #define PLUGIN_DATE "January 2008"
22 #define PLUGIN_VERSION "1"
23 #define PLUGIN_DESCRIPTION "Test File Daemon Plugin"
25 /* Forward referenced functions */
26 static bRC newPlugin(bpContext *ctx);
27 static bRC freePlugin(bpContext *ctx);
28 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value);
29 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value);
30 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value);
31 static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp);
32 static bRC endBackupFile(bpContext *ctx);
33 static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
34 static bRC startRestoreFile(bpContext *ctx, const char *cmd);
35 static bRC endRestoreFile(bpContext *ctx);
36 static bRC createFile(bpContext *ctx, struct restore_pkt *rp);
37 static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp);
40 /* Pointers to Bacula functions */
41 static bFuncs *bfuncs = NULL;
42 static bInfo *binfo = NULL;
44 static pInfo pluginInfo = {
46 FD_PLUGIN_INTERFACE_VERSION,
55 static pFuncs pluginFuncs = {
57 FD_PLUGIN_INTERFACE_VERSION,
59 /* Entry points into plugin */
60 newPlugin, /* new plugin instance */
61 freePlugin, /* free plugin instance */
74 bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
76 bfuncs = lbfuncs; /* set Bacula funct pointers */
78 printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
80 *pinfo = &pluginInfo; /* return pointer to our info */
81 *pfuncs = &pluginFuncs; /* return pointer to our functions */
88 printf("plugin: Unloaded\n");
92 static bRC newPlugin(bpContext *ctx)
95 bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
96 // printf("plugin: newPlugin JobId=%d\n", JobId);
97 bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
101 static bRC freePlugin(bpContext *ctx)
104 bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
105 // printf("plugin: freePlugin JobId=%d\n", JobId);
109 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value)
111 // printf("plugin: getPluginValue var=%d\n", var);
115 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value)
117 // printf("plugin: setPluginValue var=%d\n", var);
121 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
125 switch (event->eventType) {
127 printf("plugin: JobStart=%s\n", (char *)value);
130 printf("plugin: JobEnd\n");
132 case bEventStartBackupJob:
133 printf("plugin: BackupStart\n");
135 case bEventEndBackupJob:
136 printf("plugin: BackupEnd\n");
139 printf("plugin: JobLevel=%c %d\n", (int)value, (int)value);
142 printf("plugin: since=%d\n", (int)value);
144 case bEventStartRestoreJob:
145 printf("plugin: StartRestoreJob\n");
147 case bEventEndRestoreJob:
148 printf("plugin: EndRestoreJob\n");
151 /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
152 case bEventRestoreCommand:
153 printf("plugin: backup command=%s\n", (char *)value);
156 case bEventBackupCommand:
157 printf("plugin: backup command=%s\n", (char *)value);
161 printf("plugin: unknown event=%d\n", event->eventType);
163 bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
164 // printf("FD Name=%s\n", name);
165 // bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
166 // bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
170 static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp)
175 static bRC endBackupFile(bpContext *ctx)
183 static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
189 printf("plugin: IO_OPEN\n");
192 printf("plugin: IO_READ buf=%p len=%d\n", io->buf, io->count);
195 printf("plugin: IO_WRITE buf=%p len=%d\n", io->buf, io->count);
198 printf("plugin: IO_CLOSE\n");
204 static bRC startRestoreFile(bpContext *ctx, const char *cmd)
209 static bRC endRestoreFile(bpContext *ctx)
214 static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
219 static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp)