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  * Common plugin definitions
29  */
30 #ifndef BAREOS_LIB_PLUGINS_H_
31 #define BAREOS_LIB_PLUGINS_H_
32 
33 /****************************************************************************
34  *                                                                          *
35  *                Common definitions for all plugins                        *
36  *                                                                          *
37  ****************************************************************************/
38 
39 /**
40  * Universal return codes from all plugin functions
41  */
42 typedef enum
43 {
44   PYTHON_UNDEFINED_RETURN_VALUE = -1,
45   bRC_OK = 0,     /* OK */
46   bRC_Stop = 1,   /* Stop calling other plugins */
47   bRC_Error = 2,  /* Some kind of error */
48   bRC_More = 3,   /* More files to backup */
49   bRC_Term = 4,   /* Unload me */
50   bRC_Seen = 5,   /* Return code from checkFiles */
51   bRC_Core = 6,   /* Let BAREOS core handles this file */
52   bRC_Skip = 7,   /* Skip the proposed file */
53   bRC_Cancel = 8, /* Job cancelled */
54 
55   bRC_Max = 9999 /* Max code BAREOS can use */
56 } bRC;
57 
58 #define LOWEST_PLUGIN_INSTANCE 0
59 #define HIGHEST_PLUGIN_INSTANCE 127
60 
61 extern "C" {
62 typedef bRC (*t_loadPlugin)(void* binfo,
63                             void* bfuncs,
64                             void** pinfo,
65                             void** pfuncs);
66 typedef bRC (*t_unloadPlugin)(void);
67 }
68 
69 class Plugin {
70  public:
71   char* file;
72   int32_t file_len;
73   t_unloadPlugin unloadPlugin;
74   void* pinfo;
75   void* pfuncs;
76   void* pHandle;
77 };
78 
79 /**
80  * Context packet as first argument of all functions
81  */
82 struct bpContext {
83   uint32_t instance;
84   Plugin* plugin;
85   void* bContext; /* BAREOS private context */
86   void* pContext; /* Plugin private context */
87 };
88 
89 typedef struct gen_pluginInfo {
90   uint32_t size;
91   uint32_t version;
92   const char* plugin_magic;
93   const char* plugin_license;
94   const char* plugin_author;
95   const char* plugin_date;
96   const char* plugin_version;
97   const char* plugin_description;
98   const char* plugin_usage;
99 } genpInfo;
100 
101 class alist;
102 
103 /* Functions */
104 bool LoadPlugins(void* binfo,
105                  void* bfuncs,
106                  alist* plugin_list,
107                  const char* plugin_dir,
108                  alist* plugin_names,
109                  const char* type,
110                  bool IsPluginCompatible(Plugin* plugin));
111 void UnloadPlugins(alist* plugin_list);
112 void UnloadPlugin(alist* plugin_list, Plugin* plugin, int index);
113 int ListPlugins(alist* plugin_list, PoolMem& msg);
114 
115 /* Each daemon can register a debug hook that will be called
116  * after a fatal signal
117  */
118 typedef void(dbg_plugin_hook_t)(Plugin* plug, FILE* fp);
119 void DbgPluginAddHook(dbg_plugin_hook_t* fct);
120 typedef void(dbg_print_plugin_hook_t)(FILE* fp);
121 void DbgPrintPluginAddHook(dbg_print_plugin_hook_t* fct);
122 void DumpPlugins(alist* plugin_list, FILE* fp);
123 
124 #endif /* BAREOS_LIB_PLUGINS_H_ */
125