/[pdpsoft]/trunk/grid-mw-security/ees/src/plugin_manager/plugin_manager.c
ViewVC logotype

Contents of /trunk/grid-mw-security/ees/src/plugin_manager/plugin_manager.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 572 - (show annotations) (download) (as text)
Mon Jul 20 13:31:12 2009 UTC (12 years, 6 months ago) by aramv
File MIME type: text/x-chdr
File size: 4921 byte(s)
Added check for flex to determine of yylex_destroy() can be used
1 #include "plugin_manager.h"
2 #include "_plugin_manager.h"
3 #include <string.h>
4
5 lcmaps_plugindl_t * get_running_plugin(){
6 return _running_plugin;
7 }
8
9 void set_running_plugin(lcmaps_plugindl_t * plugin){
10 _running_plugin = plugin;
11 }
12
13 NG_RC add_plugin(char* plugin, int argc, char* argv[]){
14 return NG_FAILURE;
15 }
16
17 /* returns 1 on errors, 0 for success */
18 NG_RC startPluginManager(){
19 plugin_list = NULL;
20 _running_plugin = NULL;
21 // PluginInit returns NULL if plugin failed to load.
22 /*plugin_list = PluginInit("plugin_a", 1, NULL);*/
23 /*if(plugin_list == NULL){*/
24 /*return 1;*/
25 /*}*/
26
27 /*plugin_list->next = PluginInit("plugin_b", 1, NULL);*/
28 /*if(plugin_list->next == NULL){*/
29 /*return 1;*/
30 /*}*/
31
32 /* success */
33 return 0;
34 }
35
36 NG_RC clean_plugin_list(lcmaps_plugindl_t * list){
37 lcmaps_plugindl_t * plugin_entry=NULL;
38 lcmaps_plugindl_t * plugin_next=NULL;
39 plugin_entry=list;
40
41 while(plugin_entry){
42 plugin_next = plugin_entry->next;
43 if(dlclose(plugin_entry->handle)){
44 ng_log(0, "ees.clean_plugin_list(): dlclose error %s\n", dlerror());
45 return 1;
46 }
47 free(plugin_entry);
48 plugin_entry = plugin_next;
49 }
50 list = plugin_entry = plugin_next = NULL;
51 return 0;
52 }
53
54 /* Wrapper for dlsym with error logging. Adapted from lcmaps_pluginmanager.c get_procsymbol */
55 lcmaps_proc_t get_procsymbol(void* handle, char* symname){
56 lcmaps_proc_t symhandle;
57 symhandle = dlsym(handle,symname);
58 char* errstring;
59 if((errstring = dlerror()) != NULL){
60 ng_log(0, "ees.get_procsymbol(): dlsym error %s\n", errstring);
61 return NULL;
62 }
63 return symhandle;
64 }
65
66 lcmaps_plugindl_t * PluginInit(char *plugin_name, int argc, char** argv){
67
68 memset(abs_plugin_path, 0, LCMAPS_MAXPATHLEN);
69 lcmaps_plugindl_t * current_plugin = NULL;
70
71 /*TODO maak safe(r) */
72 if(!(strcat(abs_plugin_path, MODULE_DIR) && \
73 strcat(abs_plugin_path, plugin_name) && \
74 strcat(abs_plugin_path, ".mod"))){
75 goto fail_startPluginManager;
76 }
77
78 /* current plugin struct */
79 current_plugin = calloc(1,sizeof(lcmaps_plugindl_t));
80
81 ng_log(LOG_ERR, "Loading plugin %s\n", &abs_plugin_path);
82
83 /* load plugin handle */
84 current_plugin->handle = dlopen(abs_plugin_path, RTLD_NOW);
85
86 strncpy(current_plugin->pluginname, plugin_name, LCMAPS_MAXPATHLEN);
87 /*current_plugin->pluginname = plugin_name;*/
88 /**(current_plugin->pluginargs) = *plugin_name;*/
89
90 if(!current_plugin->handle){
91 ng_log(LOG_ERR, "%s", dlerror());
92 exit(1);
93 }
94
95 if(dlerror()){
96 ng_log(LOG_ERR, "%s", errno);
97 exit(1);
98 }
99
100 current_plugin->procs[INITPROC] = NULL;
101
102 /* link function pointers */
103 current_plugin->procs[INITPROC] = get_procsymbol(current_plugin->handle, "plugin_initialize");
104 if(current_plugin->procs[INITPROC] == NULL){
105 ng_log(LOG_ERR,"ees.mod-PluginInit(): plugin %s not compliant\n", current_plugin->pluginname);
106 goto fail_startPluginManager;
107 }
108
109 current_plugin->procs[RUNPROC] = get_procsymbol(current_plugin->handle, "plugin_run");
110 if(current_plugin->procs[RUNPROC] == NULL){
111 ng_log(LOG_ERR, "ees.runPlugin\n");
112 goto fail_startPluginManager;
113 }
114
115 current_plugin->procs[TERMPROC] = get_procsymbol(current_plugin->handle, "plugin_terminate");
116 if(current_plugin->procs[TERMPROC] == NULL){
117 ng_log(LOG_ERR, "ees.termPlugin\n");
118 goto fail_startPluginManager;
119 }
120
121 set_running_plugin(current_plugin);
122
123 init_fnc_ptr = current_plugin->procs[INITPROC];
124
125 /* call function pointer */
126 if(init_fnc_ptr(argc, argv) == NG_PL_FAILURE){
127 goto fail_startPluginManager;
128 }
129
130 print_lcmaps_plugin(0, current_plugin);
131
132 /* return plugin struct */
133 return current_plugin;
134
135 fail_startPluginManager:
136 clean_plugin_list(current_plugin);
137 return NULL;
138 }
139
140 NG_RC print_lcmaps_plugin(int debug_lvl, lcmaps_plugindl_t *plugin){
141 ng_log(debug_lvl, "plugin name : %s\n", plugin->pluginname);
142 return 0;
143 }
144
145 lcmaps_plugindl_t* get_plugin(char* plugin_name){
146 lcmaps_plugindl_t * current_plugin = plugin_list;
147 while(current_plugin != NULL){
148 print_lcmaps_plugin(LOG_DEBUG, current_plugin);
149 if(strcmp(current_plugin->pluginname, plugin_name) == 0){
150 return current_plugin;
151 }
152 current_plugin = current_plugin->next;
153 }
154 return NULL;
155 }
156
157 NG_RC runPlugin(char* plugin_name){
158 lcmaps_plugindl_t * current_plugin;
159 current_plugin = get_plugin(plugin_name);
160 run_fnc_ptr = current_plugin->procs[RUNPROC];
161 ng_log(LOG_DEBUG, "Run method for %s linked at %p\n", plugin_name, run_fnc_ptr);
162 set_running_plugin(current_plugin);
163 run_fnc_ptr();
164 return NG_SUCCESS;
165 }
166
167 /* basically hetzelfde als de runPlugin functie */
168 NG_RC termPlugin(char* plugin_name){
169 lcmaps_plugindl_t * current_plugin;
170 current_plugin = get_plugin(plugin_name);
171 term_fnc_ptr = current_plugin->procs[TERMPROC];
172 ng_log(LOG_DEBUG, "Run method for %s linked at %p\n", plugin_name, term_fnc_ptr);
173 set_running_plugin(current_plugin);
174 term_fnc_ptr();
175 return NG_SUCCESS;
176 }
177
178 NG_RC stopPluginManager(){
179 clean_plugin_list(plugin_list);
180 return NG_SUCCESS;
181 }

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28