]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/fd_plugins.h
Add new features in plugin
[bacula/bacula] / bacula / src / filed / fd_plugins.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2011 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 three of the GNU Affero 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 Affero 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 Kern Sibbald.
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  * Application Programming Interface (API) definition for Bacula Plugins
30  *
31  * Kern Sibbald, October 2007
32  *
33  */
34  
35 #ifndef __FD_PLUGINS_H 
36 #define __FD_PLUGINS_H
37
38 #ifndef _BACULA_H
39 #ifdef __cplusplus
40 /* Workaround for SGI IRIX 6.5 */
41 #define _LANGUAGE_C_PLUS_PLUS 1
42 #endif
43 #define _REENTRANT    1
44 #define _THREAD_SAFE  1
45 #define _POSIX_PTHREAD_SEMANTICS 1
46 #define _FILE_OFFSET_BITS 64
47 #define _LARGEFILE_SOURCE 1
48 #define _LARGE_FILES 1
49 #endif  /* ! _BACULA_H */
50
51 #include <sys/types.h>
52
53 #if defined(HAVE_WIN32)
54 #if defined(HAVE_MINGW)
55 #include "mingwconfig.h"
56 #else
57 #include "winconfig.h"
58 #endif
59 #else  /* !HAVE_WIN32 */
60 #ifndef __CONFIG_H
61 #include "config.h"
62 #define __CONFIG_H
63 #endif
64 #endif
65
66 #include "../src/version.h"
67 #include "bc_types.h"
68 #include "lib/plugins.h"
69 #include <sys/stat.h>
70 #ifdef HAVE_WIN32
71 #include "../win32/filed/vss.h"
72 #endif
73
74 /*
75  * This packet is used for the restore objects
76  *  It is passed to the plugin when restoring
77  *  the object.
78  */
79 struct restore_object_pkt {
80    int32_t pkt_size;                  /* size of this packet */
81    char *object_name;                 /* Object name */
82    char *object;                      /* restore object data to save */
83    char *plugin_name;                 /* Plugin name */
84    int32_t object_type;               /* FT_xx for this file */             
85    int32_t object_len;                /* restore object length */
86    int32_t object_full_len;           /* restore object uncompressed length */
87    int32_t object_index;              /* restore object index */
88    int32_t object_compression;        /* set to compression type */
89    int32_t stream;                    /* attribute stream id */
90    uint32_t JobId;                    /* JobId object came from */
91    int32_t pkt_end;                   /* end packet sentinel */
92 };
93
94 /*
95  * This packet is used for file save info transfer.
96 */
97 struct save_pkt {
98    int32_t pkt_size;                  /* size of this packet */
99    char *fname;                       /* Full path and filename */
100    char *link;                        /* Link name if any */
101    struct stat statp;                 /* System stat() packet for file */
102    int32_t type;                      /* FT_xx for this file */             
103    uint32_t flags;                    /* Bacula internal flags */
104    bool portable;                     /* set if data format is portable */
105    char *cmd;                         /* command */
106    uint32_t delta_seq;                /* Delta sequence number */
107    char *object_name;                 /* Object name to create */
108    char *object;                      /* restore object data to save */
109    int32_t object_len;                /* restore object length */
110    int32_t index;                     /* restore object index */
111    int32_t pkt_end;                   /* end packet sentinel */
112 };
113
114 /*
115  * This packet is used for file restore info transfer.
116 */
117 struct restore_pkt {
118    int32_t pkt_size;                  /* size of this packet */
119    int32_t stream;                    /* attribute stream id */
120    int32_t data_stream;               /* id of data stream to follow */
121    int32_t type;                      /* file type FT */
122    int32_t file_index;                /* file index */
123    int32_t LinkFI;                    /* file index to data if hard link */
124    uid_t uid;                         /* userid */
125    struct stat statp;                 /* decoded stat packet */
126    const char *attrEx;                /* extended attributes if any */
127    const char *ofname;                /* output filename */
128    const char *olname;                /* output link name */
129    const char *where;                 /* where */
130    const char *RegexWhere;            /* regex where */
131    int replace;                       /* replace flag */
132    int create_status;                 /* status from createFile() */
133    uint32_t delta_seq;                /* Delta sequence number */
134    int32_t pkt_end;                   /* end packet sentinel */
135 };
136
137 enum {
138    IO_OPEN = 1,
139    IO_READ = 2,
140    IO_WRITE = 3,
141    IO_CLOSE = 4,
142    IO_SEEK = 5
143 };
144
145 struct io_pkt {
146    int32_t pkt_size;                  /* Size of this packet */
147    int32_t func;                      /* Function code */
148    int32_t count;                     /* read/write count */
149    int32_t flags;                     /* Open flags */
150    mode_t mode;                       /* permissions for created files */
151    char *buf;                         /* read/write buffer */
152    const char *fname;                 /* open filename */
153    int32_t status;                    /* return status */
154    int32_t io_errno;                  /* errno code */  
155    int32_t lerror;                    /* Win32 error code */
156    int32_t whence;                    /* lseek argument */
157    boffset_t offset;                  /* lseek argument */
158    bool win32;                        /* Win32 GetLastError returned */
159    int32_t pkt_end;                   /* end packet sentinel */
160 };
161
162 /****************************************************************************
163  *                                                                          *
164  *                Bacula definitions                                        *
165  *                                                                          *
166  ****************************************************************************/
167
168 /* Bacula Variable Ids */
169 typedef enum {
170   bVarJobId     = 1,
171   bVarFDName    = 2,
172   bVarLevel     = 3,
173   bVarType      = 4,
174   bVarClient    = 5,
175   bVarJobName   = 6,
176   bVarJobStatus = 7,
177   bVarSinceTime = 8,
178   bVarAccurate  = 9,
179   bVarFileSeen  = 10,
180   bVarVssObject = 11,
181   bVarVssDllHandle = 12,
182   bVarWorkingDir = 13,
183   bVarWhere      = 14,
184   bVarRegexWhere = 15,
185   bVarExePath    = 16,
186   bVarVersion    = 17,
187   bVarDistName   = 18,
188   bVarBEEF       = 19
189 } bVariable;
190
191 /* Events that are passed to plugin */
192 typedef enum {
193   bEventJobStart                        = 1,
194   bEventJobEnd                          = 2,
195   bEventStartBackupJob                  = 3,
196   bEventEndBackupJob                    = 4,
197   bEventStartRestoreJob                 = 5,
198   bEventEndRestoreJob                   = 6,
199   bEventStartVerifyJob                  = 7,
200   bEventEndVerifyJob                    = 8,
201   bEventBackupCommand                   = 9,
202   bEventRestoreCommand                  = 10,
203   bEventEstimateCommand                 = 11,
204   bEventLevel                           = 12,
205   bEventSince                           = 13,
206   bEventCancelCommand                   = 14, /* Executed by another thread */
207   bEventVssBackupAddComponents          = 15, /* Just before bEventVssPrepareSnapshot */
208   bEventVssRestoreLoadComponentMetadata = 16,
209   bEventVssRestoreSetComponentsSelected = 17,
210   bEventRestoreObject                   = 18,
211   bEventEndFileSet                      = 19,
212   bEventPluginCommand                   = 20, /* Sent during FileSet creation */
213   bEventVssBeforeCloseRestore           = 21,
214
215   /* Add drives to VSS snapshot 
216    *  argument: char[27] drivelist
217    * You need to add them without duplicates, 
218    * see fd_common.h add_drive() copy_drives() to get help
219    */
220   bEventVssPrepareSnapshot              = 22,
221   bEventOptionPlugin                    = 23,
222   bEventHandleBackupFile                = 24 /* Used with Options Plugin */
223 } bEventType;
224
225 typedef struct s_bEvent {
226    uint32_t eventType;
227 } bEvent;
228
229 typedef struct s_baculaInfo {
230    uint32_t size;
231    uint32_t version;
232 } bInfo;
233
234 /* Bacula Core Routines -- not used within a plugin */
235 #ifdef FILE_DAEMON
236 struct BFILE;                   /* forward referenced */
237 struct FF_PKT;
238 void load_fd_plugins(const char *plugin_dir);
239 void new_plugins(JCR *jcr);
240 void free_plugins(JCR *jcr);
241 void generate_plugin_event(JCR *jcr, bEventType event, void *value=NULL);
242 bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start);
243 bool plugin_name_stream(JCR *jcr, char *name);    
244 int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace);
245 bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd);
246 int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
247 int plugin_estimate(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
248 bool plugin_check_file(JCR *jcr, char *fname);
249 bRC plugin_option_handle_file(JCR *jcr, FF_PKT *ff_pkt, struct save_pkt *sp);
250 #endif
251
252 #ifdef __cplusplus
253 extern "C" {
254 #endif
255
256 /* 
257  * Bacula interface version and function pointers -- 
258  *  i.e. callbacks from the plugin to Bacula
259  */
260 typedef struct s_baculaFuncs {  
261    uint32_t size;
262    uint32_t version;
263    bRC (*registerBaculaEvents)(bpContext *ctx, ...);
264    bRC (*getBaculaValue)(bpContext *ctx, bVariable var, void *value);
265    bRC (*setBaculaValue)(bpContext *ctx, bVariable var, void *value);
266    bRC (*JobMessage)(bpContext *ctx, const char *file, int line, 
267        int type, utime_t mtime, const char *fmt, ...);     
268    bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
269        int level, const char *fmt, ...);
270    void *(*baculaMalloc)(bpContext *ctx, const char *file, int line, 
271        size_t size);
272    void (*baculaFree)(bpContext *ctx, const char *file, int line, void *mem);
273    bRC (*AddExclude)(bpContext *ctx, const char *file);
274    bRC (*AddInclude)(bpContext *ctx, const char *file);
275    bRC (*AddOptions)(bpContext *ctx, const char *opts);
276    bRC (*AddRegex)(bpContext *ctx, const char *item, int type);
277    bRC (*AddWild)(bpContext *ctx, const char *item, int type);
278    bRC (*NewOptions)(bpContext *ctx);
279    bRC (*NewInclude)(bpContext *ctx);
280    bRC (*NewPreInclude)(bpContext *ctx);
281    bRC (*checkChanges)(bpContext *ctx, struct save_pkt *sp);
282 } bFuncs;
283
284
285
286
287 /****************************************************************************
288  *                                                                          *
289  *                Plugin definitions                                        *
290  *                                                                          *
291  ****************************************************************************/
292
293 typedef enum {
294   pVarName = 1,
295   pVarDescription = 2
296 } pVariable;
297
298
299 #define FD_PLUGIN_MAGIC     "*FDPluginData*" 
300 #define FD_PLUGIN_INTERFACE_VERSION  5
301
302 typedef struct s_pluginInfo {
303    uint32_t size;
304    uint32_t version;
305    const char *plugin_magic;
306    const char *plugin_license;
307    const char *plugin_author;
308    const char *plugin_date;
309    const char *plugin_version;
310    const char *plugin_description;
311 } pInfo;
312
313 /*
314  * This is a set of function pointers that Bacula can call
315  *  within the plugin.
316  */
317 typedef struct s_pluginFuncs {  
318    uint32_t size;
319    uint32_t version;
320    bRC (*newPlugin)(bpContext *ctx);
321    bRC (*freePlugin)(bpContext *ctx);
322    bRC (*getPluginValue)(bpContext *ctx, pVariable var, void *value);
323    bRC (*setPluginValue)(bpContext *ctx, pVariable var, void *value);
324    bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value);
325    bRC (*startBackupFile)(bpContext *ctx, struct save_pkt *sp);
326    bRC (*endBackupFile)(bpContext *ctx);
327    bRC (*startRestoreFile)(bpContext *ctx, const char *cmd);
328    bRC (*endRestoreFile)(bpContext *ctx);
329    bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io);
330    bRC (*createFile)(bpContext *ctx, struct restore_pkt *rp);
331    bRC (*setFileAttributes)(bpContext *ctx, struct restore_pkt *rp);
332    bRC (*checkFile)(bpContext *ctx, char *fname);
333 } pFuncs;
334
335 #define plug_func(plugin) ((pFuncs *)(plugin->pfuncs))
336 #define plug_info(plugin) ((pInfo *)(plugin->pinfo))
337
338 #ifdef __cplusplus
339 }
340 #endif
341
342 #endif /* __FD_PLUGINS_H */