2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation, which is
11 listed in the file LICENSE.
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 General Public License for more details.
18 You should have received a copy of the GNU 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
23 Bacula® is a registered trademark of John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Bacula File daemon core code for loading and running plugins.
31 * Kern Sibbald, October 2007
34 #include "lib/plugin.h"
35 #include "fd-plugins.h"
37 const char *plugin_type = "-fd.so";
40 /* Forward referenced functions */
41 static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value);
42 static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value);
43 static bpError baculaRegisterEvents(bpContext *ctx, ...);
44 static bpError baculaJobMsg(bpContext *ctx, const char *file, int line,
45 int type, time_t mtime, const char *msg);
46 static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line,
47 int level, const char *msg);
50 static bInfo binfo = {
55 /* Bacula entry points */
56 static bFuncs bfuncs = {
67 void init_fd_plugins(const char *plugin_dir)
75 plugin_list = New(alist(10, not_owned_by_alist));
77 load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type);
81 * Create a new instance of each plugin for this Job
83 void new_fd_plugins(JCR *jcr)
89 int num = plugin_list->size();
95 jcr->plugin_ctx = (bpContext **)malloc(sizeof(bpContext) * num);
97 ctx = jcr->plugin_ctx;
98 foreach_alist(plugin, plugin_list) {
99 /* Start a new instance of each plugin */
100 ctx[i].bContext = (void *)jcr;
101 ctx[i].pContext = NULL;
102 plug_func(plugin)->newPlugin(ctx[i++]);
107 * Free the plugin instances for this Job
109 void free_fd_plugins(JCR *jcr)
115 ctx = jcr->plugin_ctx;
116 foreach_alist(plugin, jcr->plugin_list) {
117 /* Free the plugin instance */
118 plug_func(plugin)->freePlugin(ctx[i++]);
121 jcr->plugin_ctx = NULL;
124 void term_fd_plugins()
129 static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
131 printf("bacula: baculaGetValue var=%d\n", var);
137 *((int *)value) = 100;
140 *((char **)value) = "FD Name";
153 static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value)
155 printf("bacula: baculaSetValue var=%d\n", var);
159 static bpError baculaRegisterEvents(bpContext *ctx, ...)
165 while ((event = va_arg(args, uint32_t))) {
166 printf("Plugin wants event=%u\n", event);
172 static bpError baculaJobMsg(bpContext *ctx, const char *file, int line,
173 int type, time_t mtime, const char *msg)
175 printf("Job message: %s:%d type=%d time=%ld msg=%s\n",
176 file, line, type, mtime, msg);
180 static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line,
181 int level, const char *msg)
183 printf("Debug message: %s:%d level=%d msg=%s\n",
184 file, line, level, msg);