]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/fd/example-plugin-fd.c
935ef6ef9f34c9f8d161ee9dacfef2a2f60d0153
[bacula/bacula] / bacula / src / plugins / fd / example-plugin-fd.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
5
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.
12
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.
17
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
21    02110-1301, USA.
22
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.
27 */
28 /*
29  * Sample Plugin program
30  *
31  *  Kern Sibbald, October 2007
32  *
33  */
34 #include <stdio.h>
35 #include "fd-plugins.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
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"
46
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 endPluginBackup(bpContext *ctx);
55 static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
56 static bRC startRestoreFile(bpContext *ctx, const char *cmd);
57 static bRC endRestoreFile(bpContext *ctx);
58 static bRC createFile(bpContext *ctx, struct restore_pkt *rp);
59 static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp);
60
61
62 /* Pointers to Bacula functions */
63 static bFuncs *bfuncs = NULL;
64 static bInfo  *binfo = NULL;
65
66 static pInfo pluginInfo = {
67    sizeof(pluginInfo),
68    PLUGIN_INTERFACE_VERSION,
69    PLUGIN_MAGIC,
70    PLUGIN_LICENSE,
71    PLUGIN_AUTHOR,
72    PLUGIN_DATE,
73    PLUGIN_VERSION,
74    PLUGIN_DESCRIPTION,
75 };
76
77 static pFuncs pluginFuncs = {
78    sizeof(pluginFuncs),
79    PLUGIN_INTERFACE_VERSION,
80
81    /* Entry points into plugin */
82    newPlugin,                         /* new plugin instance */
83    freePlugin,                        /* free plugin instance */
84    getPluginValue,
85    setPluginValue,
86    handlePluginEvent,
87    startPluginBackup,
88    endPluginBackup,
89    startRestoreFile,
90    endRestoreFile,
91    pluginIO,
92    createFile,
93    setFileAttributes
94 };
95
96 bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
97 {
98    bfuncs = lbfuncs;                  /* set Bacula funct pointers */
99    binfo  = lbinfo;
100    printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
101
102    *pinfo  = &pluginInfo;             /* return pointer to our info */
103    *pfuncs = &pluginFuncs;            /* return pointer to our functions */
104
105    return bRC_OK;
106 }
107
108 bRC unloadPlugin() 
109 {
110    printf("plugin: Unloaded\n");
111    return bRC_OK;
112 }
113
114 static bRC newPlugin(bpContext *ctx)
115 {
116    int JobId = 0;
117    bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
118 // printf("plugin: newPlugin JobId=%d\n", JobId);
119    bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
120    return bRC_OK;
121 }
122
123 static bRC freePlugin(bpContext *ctx)
124 {
125    int JobId = 0;
126    bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
127 // printf("plugin: freePlugin JobId=%d\n", JobId);
128    return bRC_OK;
129 }
130
131 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value) 
132 {
133 // printf("plugin: getPluginValue var=%d\n", var);
134    return bRC_OK;
135 }
136
137 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value) 
138 {
139 // printf("plugin: setPluginValue var=%d\n", var);
140    return bRC_OK;
141 }
142
143 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
144 {
145    char *name;
146
147    switch (event->eventType) {
148    case bEventJobStart:
149       printf("plugin: JobStart=%s\n", (char *)value);
150       break;
151    case bEventJobEnd:
152       printf("plugin: JobEnd\n");
153       break;
154    case bEventBackupStart:
155       printf("plugin: BackupStart\n");
156       break;
157    case bEventBackupEnd:
158       printf("plugin: BackupEnd\n");
159       break;
160    case bEventLevel:
161       printf("plugin: JobLevel=%c %d\n", (int)value, (int)value);
162       break;
163    case bEventSince:
164       printf("plugin: since=%d\n", (int)value);
165       break;
166    case bEventRestoreStart:
167       printf("bpipe-fd: RestoreStart\n");
168       break;
169    case bEventRestoreEnd:
170       printf("bpipe-fd: RestoreEnd\n");
171       break;
172
173    /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
174    case bEventPluginCommand:
175       printf("plugin: command=%s\n", (char *)value);
176       break;
177
178    default:
179       printf("plugin: unknown event=%d\n", event->eventType);
180    }
181    bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
182 // printf("FD Name=%s\n", name);
183 // bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
184 // bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
185    return bRC_OK;
186 }
187
188 static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp)
189 {
190    return bRC_OK;
191 }
192
193 static bRC endPluginBackup(bpContext *ctx)
194
195    return bRC_OK;
196 }
197
198 /*
199  * Do actual I/O
200  */
201 static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
202 {
203    io->status = 0;
204    io->io_errno = 0;
205    switch(io->func) {
206    case IO_OPEN:
207       printf("plugin: IO_OPEN\n");
208       break;
209    case IO_READ:
210       printf("plugin: IO_READ buf=%p len=%d\n", io->buf, io->count);
211       break;
212    case IO_WRITE:
213       printf("plugin: IO_WRITE buf=%p len=%d\n", io->buf, io->count);
214       break;
215    case IO_CLOSE:
216       printf("plugin: IO_CLOSE\n");
217       break;
218    }
219    return bRC_OK;
220 }
221
222 static bRC startRestoreFile(bpContext *ctx, const char *cmd)
223 {
224    return bRC_OK;
225 }
226
227 static bRC endRestoreFile(bpContext *ctx)
228 {
229    return bRC_OK;
230 }
231
232 static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
233 {
234    return bRC_OK;
235 }
236
237 static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp)
238 {
239    return bRC_OK;
240 }
241
242
243 #ifdef __cplusplus
244 }
245 #endif