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