1 /* 2 BAREOS® - Backup Archiving REcovery Open Sourced 3 4 Copyright (C) 2007-2011 Free Software Foundation Europe e.V. 5 Copyright (C) 2011-2012 Planets Communications B.V. 6 Copyright (C) 2013-2016 Bareos GmbH & Co. KG 7 8 This program is Free Software; you can redistribute it and/or 9 modify it under the terms of version three of the GNU Affero General Public 10 License as published by the Free Software Foundation, which is 11 listed in the file LICENSE. 12 13 This program is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Affero General Public License for more details. 17 18 You should have received a copy of the GNU Affero General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 21 02110-1301, USA. 22 */ 23 /* 24 * Kern Sibbald, October 2007 25 */ 26 /** 27 * @file 28 * Interface definition for Bareos DIR Plugins 29 */ 30 31 #ifndef BAREOS_DIRD_DIR_PLUGINS_H_ 32 #define BAREOS_DIRD_DIR_PLUGINS_H_ 33 34 #ifndef BAREOS_INCLUDE_BAREOS_H_ 35 #ifdef __cplusplus 36 /* Workaround for SGI IRIX 6.5 */ 37 #define _LANGUAGE_C_PLUS_PLUS 1 38 #endif 39 #define _REENTRANT 1 40 #define _THREAD_SAFE 1 41 #define _POSIX_PTHREAD_SEMANTICS 1 42 #define _FILE_OFFSET_BITS 64 43 #define _LARGEFILE_SOURCE 1 44 #define _LARGE_FILES 1 45 #endif 46 47 #include <sys/types.h> 48 #include "include/hostconfig.h" 49 #include "include/bc_types.h" 50 #include "lib/plugins.h" 51 52 class alist; 53 54 namespace directordaemon { 55 56 /* 57 * Bareos definitions 58 */ 59 60 /** 61 * Bareos Variable Ids (Read) 62 */ 63 typedef enum 64 { 65 bDirVarJob = 1, 66 bDirVarLevel = 2, 67 bDirVarType = 3, 68 bDirVarJobId = 4, 69 bDirVarClient = 5, 70 bDirVarNumVols = 6, 71 bDirVarPool = 7, 72 bDirVarStorage = 8, 73 bDirVarWriteStorage = 9, 74 bDirVarReadStorage = 10, 75 bDirVarCatalog = 11, 76 bDirVarMediaType = 12, 77 bDirVarJobName = 13, 78 bDirVarJobStatus = 14, 79 bDirVarPriority = 15, 80 bDirVarVolumeName = 16, 81 bDirVarCatalogRes = 17, 82 bDirVarJobErrors = 18, 83 bDirVarJobFiles = 19, 84 bDirVarSDJobFiles = 20, 85 bDirVarSDErrors = 21, 86 bDirVarFDJobStatus = 22, 87 bDirVarSDJobStatus = 23, 88 bDirVarPluginDir = 24, 89 bDirVarLastRate = 25, 90 bDirVarJobBytes = 26, 91 bDirVarReadBytes = 27 92 } brDirVariable; 93 94 /** 95 * Bareos Variable Ids (Write) 96 */ 97 typedef enum 98 { 99 bwDirVarJobReport = 1, 100 bwDirVarVolumeName = 2, 101 bwDirVarPriority = 3, 102 bwDirVarJobLevel = 4 103 } bwDirVariable; 104 105 /** 106 * Events that are passed to plugin 107 */ 108 typedef enum 109 { 110 bDirEventJobStart = 1, 111 bDirEventJobEnd = 2, 112 bDirEventJobInit = 3, 113 bDirEventJobRun = 4, 114 bDirEventVolumePurged = 5, 115 bDirEventNewVolume = 6, 116 bDirEventNeedVolume = 7, 117 bDirEventVolumeFull = 8, 118 bDirEventRecyle = 9, 119 bDirEventGetScratch = 10, 120 bDirEventNewPluginOptions = 11 121 } bDirEventType; 122 123 #define DIR_NR_EVENTS bDirEventNewPluginOptions /* keep this updated ! */ 124 125 typedef struct s_bDirEvent { 126 uint32_t eventType; 127 } bDirEvent; 128 129 typedef struct s_dirbareosInfo { 130 uint32_t size; 131 uint32_t version; 132 } bDirInfo; 133 134 #ifdef __cplusplus 135 extern "C" { 136 #endif 137 138 /** 139 * Bareos interface version and function pointers 140 */ 141 typedef struct s_dirbareosFuncs { 142 uint32_t size; 143 uint32_t version; 144 bRC (*registerBareosEvents)(bpContext* ctx, int nr_events, ...); 145 bRC (*unregisterBareosEvents)(bpContext* ctx, int nr_events, ...); 146 bRC (*getInstanceCount)(bpContext* ctx, int* ret); 147 bRC (*getBareosValue)(bpContext* ctx, brDirVariable var, void* value); 148 bRC (*setBareosValue)(bpContext* ctx, bwDirVariable var, void* value); 149 bRC (*JobMessage)(bpContext* ctx, 150 const char* file, 151 int line, 152 int type, 153 utime_t mtime, 154 const char* fmt, 155 ...); 156 bRC (*DebugMessage)(bpContext* ctx, 157 const char* file, 158 int line, 159 int level, 160 const char* fmt, 161 ...); 162 } bDirFuncs; 163 164 /** 165 * Bareos Core Routines -- not used within a plugin 166 */ 167 #ifdef DIRECTOR_DAEMON 168 void LoadDirPlugins(const char* plugin_dir, alist* plugin_names); 169 void UnloadDirPlugins(void); 170 int ListDirPlugins(PoolMem& msg); 171 void DispatchNewPluginOptions(JobControlRecord* jcr); 172 void NewPlugins(JobControlRecord* jcr); 173 void FreePlugins(JobControlRecord* jcr); 174 bRC GeneratePluginEvent(JobControlRecord* jcr, 175 bDirEventType event, 176 void* value = NULL, 177 bool reverse = false); 178 #endif 179 180 /** 181 * Plugin definitions 182 */ 183 typedef enum 184 { 185 pDirVarName = 1, 186 pDirVarDescription = 2 187 } pDirVariable; 188 189 #define DIR_PLUGIN_MAGIC "*DirPluginData*" 190 #define DIR_PLUGIN_INTERFACE_VERSION 4 191 192 typedef struct s_dirpluginFuncs { 193 uint32_t size; 194 uint32_t version; 195 bRC (*newPlugin)(bpContext* ctx); 196 bRC (*freePlugin)(bpContext* ctx); 197 bRC (*getPluginValue)(bpContext* ctx, pDirVariable var, void* value); 198 bRC (*setPluginValue)(bpContext* ctx, pDirVariable var, void* value); 199 bRC (*handlePluginEvent)(bpContext* ctx, bDirEvent* event, void* value); 200 } pDirFuncs; 201 202 #define DirplugFunc(plugin) ((pDirFuncs*)(plugin->pfuncs)) 203 #define dirplug_info(plugin) ((genpInfo*)(plugin->pinfo)) 204 205 #ifdef __cplusplus 206 } 207 #endif 208 209 } /* namespace directordaemon */ 210 #endif /* BAREOS_FILED_FD_PLUGINS_H_ */ 211