]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/dir/example-plugin-dir.c
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / plugins / dir / example-plugin-dir.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2007-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  * Sample Plugin program
22  *
23  *  Kern Sibbald, October 2007
24  *
25  */
26 #include "bacula.h"
27 #include "dir_plugins.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #define PLUGIN_LICENSE      "AGPLv3"
34 #define PLUGIN_AUTHOR       "Kern Sibbald"
35 #define PLUGIN_DATE         "January 2008"
36 #define PLUGIN_VERSION      "1"
37 #define PLUGIN_DESCRIPTION  "Test Director Daemon Plugin"
38
39 /* Forward referenced functions */
40 static bRC newPlugin(bpContext *ctx);
41 static bRC freePlugin(bpContext *ctx);
42 static bRC getPluginValue(bpContext *ctx, pDirVariable var, void *value);
43 static bRC setPluginValue(bpContext *ctx, pDirVariable var, void *value);
44 static bRC handlePluginEvent(bpContext *ctx, bDirEvent *event, void *value);
45
46
47 /* Pointers to Bacula functions */
48 static bDirFuncs *bfuncs = NULL;
49 static bDirInfo  *binfo = NULL;
50
51 static pDirInfo pluginInfo = {
52    sizeof(pluginInfo),
53    DIR_PLUGIN_INTERFACE_VERSION,
54    DIR_PLUGIN_MAGIC,
55    PLUGIN_LICENSE,
56    PLUGIN_AUTHOR,
57    PLUGIN_DATE,
58    PLUGIN_VERSION,
59    PLUGIN_DESCRIPTION
60 };
61
62 static pDirFuncs pluginFuncs = {
63    sizeof(pluginFuncs),
64    DIR_PLUGIN_INTERFACE_VERSION,
65
66    /* Entry points into plugin */
67    newPlugin,                         /* new plugin instance */
68    freePlugin,                        /* free plugin instance */
69    getPluginValue,
70    setPluginValue,
71    handlePluginEvent
72 };
73
74 bRC loadPlugin(bDirInfo *lbinfo, bDirFuncs *lbfuncs, pDirInfo **pinfo, pDirFuncs **pfuncs)
75 {
76    bfuncs = lbfuncs;                  /* set Bacula funct pointers */
77    binfo  = lbinfo;
78    printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
79
80    *pinfo  = &pluginInfo;             /* return pointer to our info */
81    *pfuncs = &pluginFuncs;            /* return pointer to our functions */
82
83    return bRC_OK;
84 }
85
86 bRC unloadPlugin() 
87 {
88    printf("plugin: Unloaded\n");
89    return bRC_OK;
90 }
91
92 static bRC newPlugin(bpContext *ctx)
93 {
94    int JobId = 0;
95    bfuncs->getBaculaValue(ctx, bDirVarJobId, (void *)&JobId);
96    printf("plugin: newPlugin JobId=%d\n", JobId);
97    bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
98    return bRC_OK;
99 }
100
101 static bRC freePlugin(bpContext *ctx)
102 {
103    int JobId = 0;
104    bfuncs->getBaculaValue(ctx, bDirVarJobId, (void *)&JobId);
105    printf("plugin: freePlugin JobId=%d\n", JobId);
106    return bRC_OK;
107 }
108
109 static bRC getPluginValue(bpContext *ctx, pDirVariable var, void *value) 
110 {
111    printf("plugin: getPluginValue var=%d\n", var);
112    return bRC_OK;
113 }
114
115 static bRC setPluginValue(bpContext *ctx, pDirVariable var, void *value) 
116 {
117    printf("plugin: setPluginValue var=%d\n", var);
118    return bRC_OK;
119 }
120
121 static bRC handlePluginEvent(bpContext *ctx, bDirEvent *event, void *value)
122 {
123    char *name;
124    int val;
125    switch (event->eventType) {
126    case bDirEventJobStart:
127       printf("plugin: HandleEvent JobStart\n");
128       break;
129    case bDirEventJobEnd:
130       printf("plugin: HandleEvent JobEnd\n");
131       bfuncs->getBaculaValue(ctx, bDirVarJob, (void *)&name);
132       printf("plugin: bDirVarJob=%s\n", name);
133       bfuncs->getBaculaValue(ctx, bDirVarJobId, (void *)&val);
134       printf("plugin: bDirVarJobId=%d\n", val);
135       bfuncs->getBaculaValue(ctx, bDirVarType, (void *)&val);
136       printf("plugin: bDirVarType=%c\n", val);
137       bfuncs->getBaculaValue(ctx, bDirVarLevel, (void *)&val);
138       printf("plugin: bDirVarLevel=%c\n", val);
139       bfuncs->getBaculaValue(ctx, bDirVarClient, (void *)&name);
140       printf("plugin: bDirVarClient=%s\n", name);
141       bfuncs->getBaculaValue(ctx, bDirVarCatalog, (void *)&name);
142       printf("plugin: bDirVarCatalog=%s\n", name);
143       bfuncs->getBaculaValue(ctx, bDirVarPool, (void *)&name);
144       printf("plugin: bDirVarPool=%s\n", name);
145       bfuncs->getBaculaValue(ctx, bDirVarStorage, (void *)&name);
146       printf("plugin: bDirVarStorage=%s\n", name);
147       bfuncs->getBaculaValue(ctx, bDirVarJobErrors, (void *)&val);
148       printf("plugin: bDirVarJobErrors=%d\n", val);
149       bfuncs->getBaculaValue(ctx, bDirVarJobFiles, (void *)&val);
150       printf("plugin: bDirVarJobFiles=%d\n", val);
151       bfuncs->getBaculaValue(ctx, bDirVarNumVols, (void *)&val);
152       printf("plugin: bDirVarNumVols=%d\n", val);
153
154       break;
155    }
156    bfuncs->getBaculaValue(ctx, bDirVarJobName, (void *)&name);
157    printf("Job Name=%s\n", name);
158    bfuncs->JobMessage(ctx, __FILE__, __LINE__, M_INFO, 0, "JobMesssage message");
159    bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
160    return bRC_OK;
161 }
162
163 #ifdef __cplusplus
164 }
165 #endif