]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/dir/main.c
A bit of crypto cleanup. More later.
[bacula/bacula] / bacula / src / plugins / dir / main.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation, which is 
11    listed in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of John Walker.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Main program to test loading and running Bacula plugins.
30  *   Destined to become Bacula pluginloader, ...
31  *
32  * Kern Sibbald, October 2007
33  */
34 #include "bacula.h"
35 #include <dlfcn.h>
36 #include "lib/plugin.h"
37 #include "plugin-dir.h"
38
39 const char *plugin_type = "-dir.so";
40
41
42 /* Forward referenced functions */
43 static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value);
44 static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value);
45
46
47 /* Bacula entry points */
48 static bFuncs bfuncs = {
49    sizeof(bFuncs),
50    PLUGIN_INTERFACE,
51    baculaGetValue,
52    baculaSetValue,
53    NULL,
54    NULL
55 };
56     
57
58
59
60 int main(int argc, char *argv[])
61 {
62    char plugin_dir[1000];
63    bpContext ctx;
64    bEvent event;
65    Plugin *plugin;
66     
67    plugin_list = New(alist(10, not_owned_by_alist));
68
69    ctx.bContext = NULL;
70    ctx.pContext = NULL;
71    getcwd(plugin_dir, sizeof(plugin_dir)-1);
72
73    load_plugins((void *)&bfuncs, plugin_dir, plugin_type);
74
75    foreach_alist(plugin, plugin_list) {
76       printf("bacula: plugin_size=%d plugin_version=%d\n", 
77               pref(plugin)->size, pref(plugin)->interface);
78       printf("License: %s\nAuthor: %s\nDate: %s\nVersion: %s\nDescription: %s\n",
79          pref(plugin)->plugin_license, pref(plugin)->plugin_author, 
80          pref(plugin)->plugin_date, pref(plugin)->plugin_version, 
81          pref(plugin)->plugin_description);
82
83       /* Start a new instance of the plugin */
84       pref(plugin)->newPlugin(&ctx);
85       event.eventType = bEventNewVolume;   
86       pref(plugin)->handlePluginEvent(&ctx, &event);
87       /* Free the plugin instance */
88       pref(plugin)->freePlugin(&ctx);
89
90       /* Start a new instance of the plugin */
91       pref(plugin)->newPlugin(&ctx);
92       event.eventType = bEventNewVolume;   
93       pref(plugin)->handlePluginEvent(&ctx, &event);
94       /* Free the plugin instance */
95       pref(plugin)->freePlugin(&ctx);
96    }
97
98    unload_plugins();
99
100    printf("bacula: OK ...\n");
101    close_memory_pool();
102    sm_dump(false);
103    return 0;
104 }
105
106 static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
107 {
108    printf("bacula: baculaGetValue var=%d\n", var);
109    if (value) {
110       *((int *)value) = 100;
111    }
112    return 0;
113 }
114
115 static bpError baculaSetValue(bpContext *ctx, bVariable var, void *value)
116 {
117    printf("bacula: baculaSetValue var=%d\n", var);
118    return 0;
119 }