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