]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/sd/example-plugin-sd.c
9f6d8b38ee4a0fb7862d3beb3d6ca00e8f398fbf
[bacula/bacula] / bacula / src / plugins / sd / example-plugin-sd.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
5
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 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    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    Bacula(R) is a registered trademark of Kern Sibbald.
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.
27 */
28 /*
29  * Sample Storage daemon Plugin program
30  *
31  *  Kern Sibbald, October 2007
32  *
33  */
34 #ifdef working
35 #include "bacula.h"
36 #include "sd_plugins.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 #define PLUGIN_LICENSE      "Bacula AGPLv3"
43 #define PLUGIN_AUTHOR       "Kern Sibbald"
44 #define PLUGIN_DATE         "November 2011"
45 #define PLUGIN_VERSION      "2"
46 #define PLUGIN_DESCRIPTION  "Test Storage Daemon Plugin"
47
48 /* Forward referenced functions */
49 static bRC newPlugin(bpContext *ctx);
50 static bRC freePlugin(bpContext *ctx);
51 static bRC getPluginValue(bpContext *ctx, psdVariable var, void *value);
52 static bRC setPluginValue(bpContext *ctx, psdVariable var, void *value);
53 static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value);
54
55
56 /* Pointers to Bacula functions */
57 static bsdFuncs *bfuncs = NULL;
58 static bsdInfo  *binfo = NULL;
59
60 static psdInfo pluginInfo = {
61    sizeof(pluginInfo),
62    SD_PLUGIN_INTERFACE_VERSION,
63    SD_PLUGIN_MAGIC,
64    PLUGIN_LICENSE,
65    PLUGIN_AUTHOR,
66    PLUGIN_DATE,
67    PLUGIN_VERSION,
68    PLUGIN_DESCRIPTION
69 };
70
71 static psdFuncs pluginFuncs = {
72    sizeof(pluginFuncs),
73    SD_PLUGIN_INTERFACE_VERSION,
74
75    /* Entry points into plugin */
76    newPlugin,                         /* new plugin instance */
77    freePlugin,                        /* free plugin instance */
78    getPluginValue,
79    setPluginValue,
80    handlePluginEvent
81 };
82
83 /*
84  * loadPlugin() and unloadPlugin() are entry points that are
85  *  exported, so Bacula can directly call these two entry points
86  *  they are common to all Bacula plugins.
87  *
88  * External entry point called by Bacula to "load the plugin
89  */
90 bRC DLL_IMP_EXP
91 loadPlugin(bsdInfo *lbinfo, bsdFuncs *lbfuncs, psdInfo **pinfo, psdFuncs **pfuncs)
92 {
93    bfuncs = lbfuncs;                /* set Bacula funct pointers */
94    binfo  = lbinfo;
95    printf("example-plugin-sd: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
96    *pinfo  = &pluginInfo;             /* return pointer to our info */
97    *pfuncs = &pluginFuncs;            /* return pointer to our functions */
98    printf("example-plugin-sd: Loaded\n");
99    return bRC_OK;
100 }
101
102 /*
103  * External entry point to unload the plugin 
104  */
105 bRC DLL_IMP_EXP
106 unloadPlugin() 
107 {
108    printf("example-plugin-sd: Unloaded\n");
109    return bRC_OK;
110 }
111
112 /*
113  * The following entry points are accessed through the function 
114  *   pointers we supplied to Bacula. Each plugin type (dir, fd, sd)
115  *   has its own set of entry points that the plugin must define.
116  */
117 /*
118  * Create a new instance of the plugin i.e. allocate our private storage
119  */
120 static bRC newPlugin(bpContext *ctx)
121 {
122    int JobId = 0;
123    bfuncs->getBaculaValue(ctx, bsdVarJobId, (void *)&JobId);
124    printf("example-plugin-sd: newPlugin JobId=%d\n", JobId);
125    bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
126    return bRC_OK;
127 }
128
129 /*
130  * Free a plugin instance, i.e. release our private storage
131  */
132 static bRC freePlugin(bpContext *ctx)
133 {
134    int JobId = 0;
135    bfuncs->getBaculaValue(ctx, bsdVarJobId, (void *)&JobId);
136    printf("example-plugin-sd: freePlugin JobId=%d\n", JobId);
137    return bRC_OK;
138 }
139
140 /*
141  * Return some plugin value (none defined)
142  */
143 static bRC getPluginValue(bpContext *ctx, psdVariable var, void *value) 
144 {
145    printf("example-plugin-sd: getPluginValue var=%d\n", var);
146    return bRC_OK;
147 }
148
149 /*
150  * Set a plugin value (none defined)
151  */
152 static bRC setPluginValue(bpContext *ctx, psdVariable var, void *value) 
153 {
154    printf("example-plugin-sd: setPluginValue var=%d\n", var);
155    return bRC_OK;
156 }
157
158 /*
159  * Handle an event that was generated in Bacula
160  */
161 static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value)
162 {
163    char *name;
164    switch (event->eventType) {
165    case bsdEventJobStart:
166       printf("example-plugin-sd: HandleEvent JobStart :%s:\n", (char *)value);
167       break;
168    case bsdEventJobEnd:
169       printf("example-plugin-sd: HandleEvent JobEnd\n");
170       break;
171    }
172    bfuncs->getBaculaValue(ctx, bsdVarJobName, (void *)&name);
173    printf("Job Name=%s\n", name);
174    bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
175    bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
176    return bRC_OK;
177 }
178
179 #ifdef __cplusplus
180 }
181 #endif
182
183 #endif /* working */