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