1 /*
2    Bacula(R) - The Network Backup Solution
3 
4    Copyright (C) 2000-2020 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  * Interface definition for Bacula Plugins
21  *
22  * Kern Sibbald, October 2007
23  *
24  */
25 
26 #ifndef __DIR_PLUGINS_H
27 #define __DIR_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
41 
42 #include <sys/types.h>
43 #ifndef __CONFIG_H
44 #define __CONFIG_H
45 #include "config.h"
46 #endif
47 #include "bc_types.h"
48 #include "lib/plugins.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
55 
56 
57 /****************************************************************************
58  *                                                                          *
59  *                Bacula definitions                                        *
60  *                                                                          *
61  ****************************************************************************/
62 
63 /* Bacula Variable Ids */       /* return value */
64 typedef enum {
65   bDirVarJob       = 1,            // string
66   bDirVarLevel     = 2,            // int
67   bDirVarType      = 3,            // int
68   bDirVarJobId     = 4,            // int
69   bDirVarClient    = 5,            // string
70   bDirVarNumVols   = 6,            // int
71   bDirVarPool      = 7,            // string
72   bDirVarStorage   = 8,            // string
73   bDirVarWriteStorage = 9,         // string
74   bDirVarReadStorage  = 10,        // string
75   bDirVarCatalog   = 11,           // string
76   bDirVarMediaType = 12,           // string
77   bDirVarJobName   = 13,           // string
78   bDirVarJobStatus = 14,           // int
79   bDirVarPriority  = 15,           // int
80   bDirVarVolumeName = 16,          // string
81   bDirVarCatalogRes = 17,          // NYI
82   bDirVarJobErrors  = 18,          // int
83   bDirVarJobFiles   = 19,          // int
84   bDirVarSDJobFiles = 20,          // int
85   bDirVarSDErrors   = 21,          // int
86   bDirVarFDJobStatus = 22,         // int
87   bDirVarSDJobStatus = 23          // int
88 } brDirVariable;
89 
90 typedef enum {
91   bwDirVarJobReport  = 1,
92   bwDirVarVolumeName = 2,
93   bwDirVarPriority   = 3,
94   bwDirVarJobLevel   = 4
95 } bwDirVariable;
96 
97 
98 typedef enum {
99   bDirEventJobStart      = 1,
100   bDirEventJobEnd        = 2,
101   bDirEventJobInit       = 3,
102   bDirEventJobRun        = 4,
103   bDirEventVolumePurged  = 5,
104   bDirEventNewVolume     = 6,
105   bDirEventNeedVolume    = 7,
106   bDirEventVolumeFull    = 8,
107   bDirEventRecyle        = 9,
108   bDirEventGetScratch    = 10
109 } bDirEventsType;
110 
111 typedef struct s_bDirEvent {
112    uint32_t eventType;
113 } bDirEvent;
114 
115 typedef struct s_dirbaculaInfo {
116    uint32_t size;
117    uint32_t version;
118 } bDirInfo;
119 
120 /* Bacula interface version and function pointers */
121 typedef struct s_dirbaculaFuncs {
122    uint32_t size;
123    uint32_t version;
124    bRC (*registerBaculaEvents)(bpContext *ctx, ...);
125    bRC (*getBaculaValue)(bpContext *ctx, brDirVariable var, void *value);
126    bRC (*setBaculaValue)(bpContext *ctx, bwDirVariable var, void *value);
127    bRC (*JobMessage)(bpContext *ctx, const char *file, int line,
128                      int type, utime_t mtime, const char *fmt, ...);
129    bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
130                        int level, const char *fmt, ...);
131 } bDirFuncs;
132 
133 /* Bacula Core Routines -- not used within a plugin */
134 #ifdef DIRECTOR_DAEMON
135 void load_dir_plugins(const char *plugin_dir);
136 void new_plugins(JCR *jcr);
137 void free_plugins(JCR *jcr);
138 int generate_plugin_event(JCR *jcr, bDirEventsType event, void *value=NULL);
139 #endif
140 
141 
142 /****************************************************************************
143  *                                                                          *
144  *                Plugin definitions                                        *
145  *                                                                          *
146  ****************************************************************************/
147 
148 typedef enum {
149   pDirVarName = 1,
150   pDirVarDescription = 2
151 } pDirVariable;
152 
153 
154 #define DIR_PLUGIN_MAGIC     "*DirPluginData*"
155 #define DIR_PLUGIN_INTERFACE_VERSION  1
156 
157 typedef struct s_dirpluginInfo {
158    uint32_t size;
159    uint32_t version;
160    const char *plugin_magic;
161    const char *plugin_license;
162    const char *plugin_author;
163    const char *plugin_date;
164    const char *plugin_version;
165    const char *plugin_description;
166 } pDirInfo;
167 
168 typedef struct s_dirpluginFuncs {
169    uint32_t size;
170    uint32_t version;
171    bRC (*newPlugin)(bpContext *ctx);
172    bRC (*freePlugin)(bpContext *ctx);
173    bRC (*getPluginValue)(bpContext *ctx, pDirVariable var, void *value);
174    bRC (*setPluginValue)(bpContext *ctx, pDirVariable var, void *value);
175    bRC (*handlePluginEvent)(bpContext *ctx, bDirEvent *event, void *value);
176 } pDirFuncs;
177 
178 #define dirplug_func(plugin) ((pDirFuncs *)(plugin->pfuncs))
179 #define dirplug_info(plugin) ((pDirInfo *)(plugin->pinfo))
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 
185 #endif /* __FD_PLUGINS_H */
186