]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/dir/example-plugin-dir.c
Make out of freespace non-fatal for removable devices -- i.e. behaves like tape
[bacula/bacula] / bacula / src / plugins / dir / example-plugin-dir.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2017 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  * Sample Plugin program
21  *
22  *  Kern Sibbald, October 2007
23  */
24 #include "bacula.h"
25 #include "dir_plugins.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #define PLUGIN_LICENSE      "AGPLv3"
32 #define PLUGIN_AUTHOR       "Kern Sibbald"
33 #define PLUGIN_DATE         "January 2008"
34 #define PLUGIN_VERSION      "1"
35 #define PLUGIN_DESCRIPTION  "Test Director Daemon Plugin"
36
37 /* Forward referenced functions */
38 static bRC newPlugin(bpContext *ctx);
39 static bRC freePlugin(bpContext *ctx);
40 static bRC getPluginValue(bpContext *ctx, pDirVariable var, void *value);
41 static bRC setPluginValue(bpContext *ctx, pDirVariable var, void *value);
42 static bRC handlePluginEvent(bpContext *ctx, bDirEvent *event, void *value);
43
44
45 /* Pointers to Bacula functions */
46 static bDirFuncs *bfuncs = NULL;
47 static bDirInfo  *binfo = NULL;
48
49 static pDirInfo pluginInfo = {
50    sizeof(pluginInfo),
51    DIR_PLUGIN_INTERFACE_VERSION,
52    DIR_PLUGIN_MAGIC,
53    PLUGIN_LICENSE,
54    PLUGIN_AUTHOR,
55    PLUGIN_DATE,
56    PLUGIN_VERSION,
57    PLUGIN_DESCRIPTION
58 };
59
60 static pDirFuncs pluginFuncs = {
61    sizeof(pluginFuncs),
62    DIR_PLUGIN_INTERFACE_VERSION,
63
64    /* Entry points into plugin */
65    newPlugin,                         /* new plugin instance */
66    freePlugin,                        /* free plugin instance */
67    getPluginValue,
68    setPluginValue,
69    handlePluginEvent
70 };
71
72 bRC loadPlugin(bDirInfo *lbinfo, bDirFuncs *lbfuncs, pDirInfo **pinfo, pDirFuncs **pfuncs)
73 {
74    bfuncs = lbfuncs;                  /* set Bacula funct pointers */
75    binfo  = lbinfo;
76    printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
77
78    *pinfo  = &pluginInfo;             /* return pointer to our info */
79    *pfuncs = &pluginFuncs;            /* return pointer to our functions */
80
81    return bRC_OK;
82 }
83
84 bRC unloadPlugin() 
85 {
86    printf("plugin: Unloaded\n");
87    return bRC_OK;
88 }
89
90 static bRC newPlugin(bpContext *ctx)
91 {
92    int JobId = 0;
93    bfuncs->getBaculaValue(ctx, bDirVarJobId, (void *)&JobId);
94    printf("plugin: newPlugin JobId=%d\n", JobId);
95    bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
96    return bRC_OK;
97 }
98
99 static bRC freePlugin(bpContext *ctx)
100 {
101    int JobId = 0;
102    bfuncs->getBaculaValue(ctx, bDirVarJobId, (void *)&JobId);
103    printf("plugin: freePlugin JobId=%d\n", JobId);
104    return bRC_OK;
105 }
106
107 static bRC getPluginValue(bpContext *ctx, pDirVariable var, void *value) 
108 {
109    printf("plugin: getPluginValue var=%d\n", var);
110    return bRC_OK;
111 }
112
113 static bRC setPluginValue(bpContext *ctx, pDirVariable var, void *value) 
114 {
115    printf("plugin: setPluginValue var=%d\n", var);
116    return bRC_OK;
117 }
118
119 static bRC handlePluginEvent(bpContext *ctx, bDirEvent *event, void *value)
120 {
121    char *name;
122    int val;
123    switch (event->eventType) {
124    case bDirEventJobStart:
125       printf("plugin: HandleEvent JobStart\n");
126       break;
127    case bDirEventJobEnd:
128       printf("plugin: HandleEvent JobEnd\n");
129       bfuncs->getBaculaValue(ctx, bDirVarJob, (void *)&name);
130       printf("plugin: bDirVarJob=%s\n", name);
131       bfuncs->getBaculaValue(ctx, bDirVarJobId, (void *)&val);
132       printf("plugin: bDirVarJobId=%d\n", val);
133       bfuncs->getBaculaValue(ctx, bDirVarType, (void *)&val);
134       printf("plugin: bDirVarType=%c\n", val);
135       bfuncs->getBaculaValue(ctx, bDirVarLevel, (void *)&val);
136       printf("plugin: bDirVarLevel=%c\n", val);
137       bfuncs->getBaculaValue(ctx, bDirVarClient, (void *)&name);
138       printf("plugin: bDirVarClient=%s\n", name);
139       bfuncs->getBaculaValue(ctx, bDirVarCatalog, (void *)&name);
140       printf("plugin: bDirVarCatalog=%s\n", name);
141       bfuncs->getBaculaValue(ctx, bDirVarPool, (void *)&name);
142       printf("plugin: bDirVarPool=%s\n", name);
143       bfuncs->getBaculaValue(ctx, bDirVarStorage, (void *)&name);
144       printf("plugin: bDirVarStorage=%s\n", name);
145       bfuncs->getBaculaValue(ctx, bDirVarJobErrors, (void *)&val);
146       printf("plugin: bDirVarJobErrors=%d\n", val);
147       bfuncs->getBaculaValue(ctx, bDirVarJobFiles, (void *)&val);
148       printf("plugin: bDirVarJobFiles=%d\n", val);
149       bfuncs->getBaculaValue(ctx, bDirVarNumVols, (void *)&val);
150       printf("plugin: bDirVarNumVols=%d\n", val);
151
152       break;
153    }
154    bfuncs->getBaculaValue(ctx, bDirVarJobName, (void *)&name);
155    printf("Job Name=%s\n", name);
156    bfuncs->JobMessage(ctx, __FILE__, __LINE__, M_INFO, 0, "JobMesssage message");
157    bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
158    return bRC_OK;
159 }
160
161 #ifdef __cplusplus
162 }
163 #endif