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