ec_curses_plugins.c (ettercap-0.8.3) | : | ec_curses_plugins.c (ettercap-0.8.3.1) | ||
---|---|---|---|---|
skipping to change at line 39 | skipping to change at line 39 | |||
/* proto */ | /* proto */ | |||
static void curses_plugin_mgmt(void); | static void curses_plugin_mgmt(void); | |||
static void curses_plugin_load(void); | static void curses_plugin_load(void); | |||
static void curses_load_plugin(const char *path, char *file); | static void curses_load_plugin(const char *path, char *file); | |||
static void curses_wdg_plugin(char active, struct plugin_ops *ops); | static void curses_wdg_plugin(char active, struct plugin_ops *ops); | |||
static void curses_refresh_plug_array(char active, struct plugin_ops *ops); | static void curses_refresh_plug_array(char active, struct plugin_ops *ops); | |||
static void curses_plug_destroy(void); | static void curses_plug_destroy(void); | |||
static void curses_select_plugin(void *plugin); | static void curses_select_plugin(void *plugin); | |||
static int curses_start_plugin(char *plugin); | ||||
static void curses_create_plug_array(void); | static void curses_create_plug_array(void); | |||
static void curses_plugin_help(void *dummy); | static void curses_plugin_help(void *dummy); | |||
/* globals */ | /* globals */ | |||
static wdg_t *wdg_plugin; | static wdg_t *wdg_plugin; | |||
static struct wdg_list *wdg_plugin_elements; | static struct wdg_list *wdg_plugin_elements; | |||
static size_t nplug; | static size_t nplug; | |||
struct wdg_menu menu_plugins[] = { {"Plugins", 'P', "", NULL }, | struct wdg_menu menu_plugins[] = { {"Plugins", 'P', "", NULL }, | |||
skipping to change at line 231 | skipping to change at line 232 | |||
SAFE_REALLOC(wdg_plugin_elements, (nplug + 1) * sizeof(struct wdg_list)); | SAFE_REALLOC(wdg_plugin_elements, (nplug + 1) * sizeof(struct wdg_list)); | |||
wdg_plugin_elements[nplug].desc = NULL; | wdg_plugin_elements[nplug].desc = NULL; | |||
wdg_plugin_elements[nplug].value = NULL; | wdg_plugin_elements[nplug].value = NULL; | |||
} | } | |||
/* | /* | |||
* callback function for a plugin | * callback function for a plugin | |||
*/ | */ | |||
static void curses_select_plugin(void *plugin) | static void curses_select_plugin(void *plugin) | |||
{ | { | |||
/* start or stop the plugin */ | ||||
curses_start_plugin(plugin); | ||||
/* refresh the array for the list widget */ | ||||
curses_plugins_update(); | ||||
} | ||||
/* | ||||
* toggle the state of a plugin | ||||
*/ | ||||
static int curses_start_plugin(char *plugin) | ||||
{ | ||||
int ret; | ||||
/* prevent the selection when the list is empty */ | /* prevent the selection when the list is empty */ | |||
if (plugin == NULL) | if (plugin == NULL) | |||
return; | return -E_NOTHANDLED; | |||
/* print the message */ | /* print the message */ | |||
if (plugin_is_activated(plugin) == 0) | if (plugin_is_activated(plugin) == 0) | |||
INSTANT_USER_MSG("Activating %s plugin...\n", plugin); | INSTANT_USER_MSG("Activating %s plugin...\n", plugin); | |||
else | else | |||
INSTANT_USER_MSG("Deactivating %s plugin...\n", plugin); | INSTANT_USER_MSG("Deactivating %s plugin...\n", plugin); | |||
/* | /* | |||
* pay attention on this ! | * pay attention on this ! | |||
* if the plugin init does not return, | * if the plugin init does not return, | |||
* we are blocked here. So it is encouraged | * we are blocked here. So it is encouraged | |||
* to write plugins which spawn a thread | * to write plugins which spawn a thread | |||
* and immediately return | * and immediately return | |||
*/ | */ | |||
if (plugin_is_activated(plugin) == 1) | if (plugin_is_activated(plugin) == 1) | |||
plugin_fini(plugin); | ret = plugin_fini(plugin); | |||
else | else | |||
plugin_init(plugin); | ret = plugin_init(plugin); | |||
/* refres the array for the list widget */ | return ret; | |||
curses_plugins_update(); | ||||
} | } | |||
void curses_plugins_update(void) | void curses_plugins_update(void) | |||
{ | { | |||
DEBUG_MSG("curses_plugins_update"); | DEBUG_MSG("curses_plugins_update"); | |||
CURSES_LOCK(pluginlist_mutex); | CURSES_LOCK(pluginlist_mutex); | |||
/* refres the array for the list widget */ | /* refres the array for the list widget */ | |||
nplug = 0; | nplug = 0; | |||
plugin_list_walk(PLP_MIN, PLP_MAX, &curses_refresh_plug_array); | plugin_list_walk(PLP_MIN, PLP_MAX, &curses_refresh_plug_array); | |||
/* refresh the list */ | /* refresh the list */ | |||
wdg_list_refresh(wdg_plugin); | wdg_list_refresh(wdg_plugin); | |||
CURSES_UNLOCK(pluginlist_mutex); | CURSES_UNLOCK(pluginlist_mutex); | |||
} | } | |||
/* | ||||
* check if plugins have been provided on CLI | ||||
* and try to start all provided plugins | ||||
*/ | ||||
void curses_autostart_plugins(void) | ||||
{ | ||||
struct plugin_list *plugin, *tmp; | ||||
DEBUG_MSG("curses_autostart_plugins()"); | ||||
/* if plugins have been defined on the CLI */ | ||||
if (!LIST_EMPTY(&EC_GBL_OPTIONS->plugins)) { | ||||
LIST_FOREACH_SAFE(plugin, &EC_GBL_OPTIONS->plugins, next, tmp) { | ||||
/* first check if the plugin exists */ | ||||
if (search_plugin(plugin->name) != E_SUCCESS) { | ||||
plugin->exists = false; | ||||
USER_MSG("Sorry, plugin '%s' can not be found - skipping\n\n", | ||||
plugin->name); | ||||
} | ||||
else { | ||||
/* now we can try to start the plugin */ | ||||
plugin->exists = true; | ||||
if (curses_start_plugin(plugin->name) != PLUGIN_RUNNING) { | ||||
USER_MSG("Plugin '%s' can not be started - skipping\n\n", | ||||
plugin->name); | ||||
} | ||||
} | ||||
} | ||||
} | ||||
} | ||||
/* EOF */ | /* EOF */ | |||
// vim:ts=3:expandtab | // vim:ts=3:expandtab | |||
End of changes. 7 change blocks. | ||||
5 lines changed or deleted | 51 lines changed or added |