]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/fd/example-plugin-fd.c
First incomplete cut of big malloc blocks for htable.
[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 startBackupFile(bpContext *ctx, struct save_pkt *sp);
54 static bRC endBackupFile(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    startBackupFile,
88    endBackupFile,
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 bEventStartBackupJob:
155       printf("plugin: BackupStart\n");
156       break;
157    case bEventEndBackupJob:
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 bEventStartRestoreJob:
167       printf("plugin: StartRestoreJob\n");
168       break;
169    case bEventEndRestoreJob:
170       printf("plugin: EndRestoreJob\");
171       break;
172
173    /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
174    case bEventRestoreCommand:
175       printf("plugin: backup command=%s\n", (char *)value);
176       break;
177
178    case bEventBackupCommand:
179       printf("plugin: backup command=%s\n", (char *)value);
180       break;
181
182    default:
183       printf("plugin: unknown event=%d\n", event->eventType);
184    }
185    bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
186 // printf("FD Name=%s\n", name);
187 // bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
188 // bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
189    return bRC_OK;
190 }
191
192 static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp)
193 {
194    return bRC_OK;
195 }
196
197 static bRC endBackupFile(bpContext *ctx)
198
199    return bRC_OK;
200 }
201
202 /*
203  * Do actual I/O
204  */
205 static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
206 {
207    io->status = 0;
208    io->io_errno = 0;
209    switch(io->func) {
210    case IO_OPEN:
211       printf("plugin: IO_OPEN\n");
212       break;
213    case IO_READ:
214       printf("plugin: IO_READ buf=%p len=%d\n", io->buf, io->count);
215       break;
216    case IO_WRITE:
217       printf("plugin: IO_WRITE buf=%p len=%d\n", io->buf, io->count);
218       break;
219    case IO_CLOSE:
220       printf("plugin: IO_CLOSE\n");
221       break;
222    }
223    return bRC_OK;
224 }
225
226 static bRC startRestoreFile(bpContext *ctx, const char *cmd)
227 {
228    return bRC_OK;
229 }
230
231 static bRC endRestoreFile(bpContext *ctx)
232 {
233    return bRC_OK;
234 }
235
236 static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
237 {
238    return bRC_OK;
239 }
240
241 static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp)
242 {
243    return bRC_OK;
244 }
245
246
247 #ifdef __cplusplus
248 }
249 #endif