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