]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/sd/main.c
Backport from BEE
[bacula/bacula] / bacula / src / plugins / sd / main.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  * Main program to test loading and running Bacula plugins.
18  *   Destined to become Bacula pluginloader, ...
19  *
20  * Kern Sibbald, October 2007
21  */
22 #include "bacula.h"
23 #include <dlfcn.h>
24 #include "lib/plugin.h"
25 #include "plugin-sd.h"
26
27 const char *plugin_type = "-sd.so";
28
29
30 /* Forward referenced functions */
31 static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value);
32 static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value);
33
34
35 /* Bacula entry points */
36 static bFuncs bfuncs = {
37    sizeof(bFuncs),
38    PLUGIN_INTERFACE,
39    baculaGetValue,
40    baculaSetValue,
41    NULL,
42    NULL
43 };
44
45
46
47
48 int main(int argc, char *argv[])
49 {
50    char plugin_dir[1000];
51    bpContext ctx;
52    bEvent event;
53    Plugin *plugin;
54
55    bplugin_list = New(alist(10, not_owned_by_alist));
56
57    ctx.bContext = NULL;
58    ctx.pContext = NULL;
59    getcwd(plugin_dir, sizeof(plugin_dir)-1);
60
61    load_plugins((void *)&bfuncs, plugin_dir, plugin_type);
62
63    foreach_alist(plugin, bplugin_list) {
64       printf("bacula: plugin_size=%d plugin_version=%d\n",
65               pref(plugin)->size, pref(plugin)->interface);
66       printf("License: %s\nAuthor: %s\nDate: %s\nVersion: %s\nDescription: %s\n",
67          pref(plugin)->plugin_license, pref(plugin)->plugin_author,
68          pref(plugin)->plugin_date, pref(plugin)->plugin_version,
69          pref(plugin)->plugin_description);
70
71       /* Start a new instance of the plugin */
72       pref(plugin)->newPlugin(&ctx);
73       event.eventType = bEventNewVolume;
74       pref(plugin)->handlePluginEvent(&ctx, &event);
75       /* Free the plugin instance */
76       pref(plugin)->freePlugin(&ctx);
77
78       /* Start a new instance of the plugin */
79       pref(plugin)->newPlugin(&ctx);
80       event.eventType = bEventNewVolume;
81       pref(plugin)->handlePluginEvent(&ctx, &event);
82       /* Free the plugin instance */
83       pref(plugin)->freePlugin(&ctx);
84    }
85
86    unload_plugins();
87
88    printf("bacula: OK ...\n");
89    close_memory_pool();
90    sm_dump(false);
91    return 0;
92 }
93
94 static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
95 {
96    printf("bacula: baculaGetValue var=%d\n", var);
97    if (value) {
98       *((int *)value) = 100;
99    }
100    return 0;
101 }
102
103 static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value)
104 {
105    printf("bacula: baculaSetValue var=%d\n", var);
106    return 0;
107 }