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