00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00036 #include <string.h>
00037
00038 #include "lcmaps_log.h"
00039 #include "evaluationmanager.h"
00040
00049 static lcmaps_db_entry_t* global_plugin_list = NULL;
00050
00051 int free_lcmaps_db_entry();
00052
00053
00062 int startEvaluationManager(const char* name)
00063 {
00064 if (pdl_init(name) < 0) {
00065 stopEvaluationManager();
00066 return -1;
00067 }
00068
00069
00070 yyparse();
00071
00072
00073
00074
00075
00076 if (yyparse_errors()) {
00077 stopEvaluationManager();
00078 return -1;
00079 }
00080
00081
00082
00083
00084
00085 reduce_policies();
00086
00087 return 0;
00088 }
00089
00090
00102 int getPluginNameAndArgs(lcmaps_db_entry_t** plugins)
00103 {
00104 const plugin_t* p_list, *tmp_p_list;
00105 int length, path_length;
00106 char* path;
00107
00108
00109 if (global_plugin_list) {
00110 *plugins = global_plugin_list;
00111 return 0;
00112 }
00113
00114
00115 *plugins = 0;
00116
00117 if (!pdl_path()) {
00118 lcmaps_log(1, "Initialization of the EvaluationManager either failed or was not done.\n");
00119 return -1;
00120 }
00121
00122 path = strdup(pdl_path());
00123 path_length = strlen(path);
00124
00125 if (path[path_length-1] != '/') {
00126 path = (char *)realloc(path, path_length+2);
00127 path[path_length] = '/';
00128 path[path_length+1] = '\0';
00129
00130 path_length = strlen(path);
00131 }
00132
00133 p_list = get_plugins();
00134
00135 while (p_list) {
00136 lcmaps_db_entry_t* p;
00137
00138 if (!*plugins) {
00139 *plugins = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00140 p = *plugins;
00141 } else {
00142 p->next = (lcmaps_db_entry_t*)malloc(sizeof(lcmaps_db_entry_t));
00143 p = p->next;
00144 }
00145
00146
00147 strncpy(p->pluginname, path, LCMAPS_MAXPATHLEN);
00148 strncpy(p->pluginname+path_length, p_list->name, LCMAPS_MAXPATHLEN-path_length);
00149
00150 if (p_list->args)
00151 strncpy(p->pluginargs, p_list->args, LCMAPS_MAXARGSTRING);
00152 else
00153 *p->pluginargs = '\0';
00154 p->next = 0;
00155
00156 tmp_p_list = p_list->next;
00157
00158 if (p_list->name) free(p_list->name);
00159 if (p_list->args) free(p_list->args);
00160 free(p_list);
00161
00162 p_list = tmp_p_list;
00163
00164
00165 lcmaps_log_debug(1, "%s\n", p->pluginname);
00166 lcmaps_log_debug(1, "%s\n", p->pluginargs);
00167 }
00168
00169 free(path);
00170
00171 global_plugin_list = *plugins;
00172
00173 return 0;
00174 }
00175
00176
00185 int runEvaluationManager(void)
00186 {
00187 const char* plugin_name;
00188 plugin_status_t result;
00189
00190 lcmaps_log_debug(1, "runEvaluationManager called\n");
00191
00192 result = EVALUATION_START;
00193 while (plugin_name=pdl_next_plugin(result)) {
00194 result = (runPlugin(plugin_name) ? EVALUATION_FAILURE : EVALUATION_SUCCESS);
00195
00196 lcmaps_log_debug(1, "runEvaluationManager: running plugin: %s.\n", plugin_name);
00197 lcmaps_log_debug(1, " : result %s.\n", (result==EVALUATION_SUCCESS) ? "true" : "false");
00198
00199 free(plugin_name);
00200 }
00201
00202 if (result==EVALUATION_START)
00203 lcmaps_log(1, "Initialization of the EvaluationManager either failed or was not done.\n");
00204
00205 return result==EVALUATION_SUCCESS ? 0 : 1;
00206 }
00207
00208
00219 int stopEvaluationManager(void)
00220 {
00221 lcmaps_log_debug(1, "stopEvaluationManager: cleaning up!\n");
00222
00223 free_resources();
00224
00225 free_lcmaps_db_entry();
00226
00227 return 0;
00228 }
00229
00230
00240 int free_lcmaps_db_entry()
00241 {
00242 lcmaps_db_entry_t* plugin = global_plugin_list;
00243
00244 while (plugin) {
00245 lcmaps_db_entry_t* tmp = plugin->next;
00246 free(plugin);
00247 plugin = tmp;
00248 }
00249
00250 global_plugin_list = NULL;
00251
00252 return 0;
00253 }