ec_gtk_plugins.c (ettercap-0.8.3) | : | ec_gtk_plugins.c (ettercap-0.8.3.1) | ||
---|---|---|---|---|
skipping to change at line 36 | skipping to change at line 36 | |||
#define MAX_DESC_LEN 75 | #define MAX_DESC_LEN 75 | |||
/* proto */ | /* proto */ | |||
static void gtkui_load_plugin(const char *full); | static void gtkui_load_plugin(const char *full); | |||
static void gtkui_add_plugin(char active, struct plugin_ops *ops); | static void gtkui_add_plugin(char active, struct plugin_ops *ops); | |||
static void gtkui_plug_destroy(void); | static void gtkui_plug_destroy(void); | |||
static void gtkui_plugins_detach(GtkWidget *child); | static void gtkui_plugins_detach(GtkWidget *child); | |||
static void gtkui_plugins_attach(void); | static void gtkui_plugins_attach(void); | |||
static void gtkui_select_plugin(void); | static int gtkui_select_plugin(gchar *plugin); | |||
static void gtkui_select_plugin_treeview(GtkTreeView *treeview, | ||||
GtkTreePath *path, GtkTreeViewColumn *column, gpointer data); | ||||
static void gtkui_create_plug_array(void); | static void gtkui_create_plug_array(void); | |||
/* globals */ | /* globals */ | |||
static GtkWidget *plugins_window = NULL; | static GtkWidget *plugins_window = NULL; | |||
static GtkWidget *treeview = NULL; | static GtkWidget *treeview = NULL; | |||
static GtkListStore *ls_plugins = NULL; | static GtkListStore *ls_plugins = NULL; | |||
static GtkTreeSelection *selection = NULL; | static GtkTreeSelection *selection = NULL; | |||
/*******************************************/ | /*******************************************/ | |||
skipping to change at line 167 | skipping to change at line 169 | |||
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADO W_IN); | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADO W_IN); | |||
gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); | gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); | |||
gtk_widget_show(scrolled); | gtk_widget_show(scrolled); | |||
treeview = gtk_tree_view_new(); | treeview = gtk_tree_view_new(); | |||
gtk_container_add(GTK_CONTAINER (scrolled), treeview); | gtk_container_add(GTK_CONTAINER (scrolled), treeview); | |||
gtk_widget_show(treeview); | gtk_widget_show(treeview); | |||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); | |||
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); | gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); | |||
g_signal_connect (G_OBJECT (treeview), "row_activated", G_CALLBACK (gtkui_sel | g_signal_connect (G_OBJECT (treeview), "row-activated", | |||
ect_plugin), NULL); | G_CALLBACK(gtkui_select_plugin_treeview), NULL); | |||
renderer = gtk_cell_renderer_text_new (); | renderer = gtk_cell_renderer_text_new (); | |||
column = gtk_tree_view_column_new_with_attributes (" ", renderer, "text", 0, NULL); | column = gtk_tree_view_column_new_with_attributes (" ", renderer, "text", 0, NULL); | |||
gtk_tree_view_column_set_sort_column_id (column, 0); | gtk_tree_view_column_set_sort_column_id (column, 0); | |||
gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); | gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); | |||
renderer = gtk_cell_renderer_text_new (); | renderer = gtk_cell_renderer_text_new (); | |||
column = gtk_tree_view_column_new_with_attributes ("Name", renderer, "text", 1, NULL); | column = gtk_tree_view_column_new_with_attributes ("Name", renderer, "text", 1, NULL); | |||
gtk_tree_view_column_set_sort_column_id (column, 1); | gtk_tree_view_column_set_sort_column_id (column, 1); | |||
gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); | gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); | |||
skipping to change at line 244 | skipping to change at line 247 | |||
DEBUG_MSG("gtk_create_plug_array"); | DEBUG_MSG("gtk_create_plug_array"); | |||
if(ls_plugins) | if(ls_plugins) | |||
gtk_list_store_clear(GTK_LIST_STORE (ls_plugins)); | gtk_list_store_clear(GTK_LIST_STORE (ls_plugins)); | |||
else | else | |||
ls_plugins = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_S TRING, G_TYPE_STRING); | ls_plugins = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_S TRING, G_TYPE_STRING); | |||
/* go thru the list of plugins */ | /* go thru the list of plugins */ | |||
res = plugin_list_walk(PLP_MIN, PLP_MAX, >kui_add_plugin); | res = plugin_list_walk(PLP_MIN, PLP_MAX, >kui_add_plugin); | |||
if (res == -E_NOTFOUND) { | if (res == -E_NOTFOUND) { | |||
blocked = g_signal_handlers_block_by_func (G_OBJECT (treeview), G_CALLBACK | blocked = g_signal_handlers_block_by_func (G_OBJECT (treeview), | |||
(gtkui_select_plugin), NULL); | G_CALLBACK(gtkui_select_plugin_treeview), NULL); | |||
gtk_list_store_append (ls_plugins, &iter); | gtk_list_store_append (ls_plugins, &iter); | |||
gtk_list_store_set (ls_plugins, &iter, 0, " ", 1, "No Plugins Loaded", -1) ; | gtk_list_store_set (ls_plugins, &iter, 0, " ", 1, "No Plugins Loaded", -1) ; | |||
} else if(blocked > 0) { | } else if(blocked > 0) { | |||
g_signal_handlers_unblock_by_func (G_OBJECT (treeview), G_CALLBACK (gtkui_ | g_signal_handlers_unblock_by_func (G_OBJECT (treeview), | |||
select_plugin), NULL); | G_CALLBACK(gtkui_select_plugin_treeview), NULL); | |||
blocked = 0; | blocked = 0; | |||
} | } | |||
} | } | |||
/* | /* | |||
* callback function for displaying the plugin list | * callback function for displaying the plugin list | |||
*/ | */ | |||
static void gtkui_add_plugin(char active, struct plugin_ops *ops) | static void gtkui_add_plugin(char active, struct plugin_ops *ops) | |||
{ | { | |||
GtkTreeIter iter; | GtkTreeIter iter; | |||
skipping to change at line 273 | skipping to change at line 278 | |||
gtk_list_store_append (ls_plugins, &iter); | gtk_list_store_append (ls_plugins, &iter); | |||
gtk_list_store_set (ls_plugins, &iter, | gtk_list_store_set (ls_plugins, &iter, | |||
0, active_str, | 0, active_str, | |||
1, ops->name, | 1, ops->name, | |||
2, ops->version, | 2, ops->version, | |||
3, ops->info, -1); | 3, ops->info, -1); | |||
} | } | |||
/* | /* | |||
* callback function for a plugin | * toggle state of a plugin | |||
*/ | */ | |||
static void gtkui_select_plugin(void) | static int gtkui_select_plugin(gchar *plugin) | |||
{ | { | |||
GtkTreeIter iter; | int ret; | |||
GtkTreeModel *model; | ||||
char *plugin = NULL; | ||||
model = GTK_TREE_MODEL (ls_plugins); | ||||
if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), &model, | ||||
&iter)) { | ||||
gtk_tree_model_get (model, &iter, 1, &plugin, -1); | ||||
} else | ||||
return; /* nothing is selected */ | ||||
if(!plugin) | if(!plugin) | |||
return; /* bad pointer from gtk_tree_model_get, shouldn't happen */ | /* bad pointer from gtk_tree_model_get, shouldn't happen */ | |||
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); | |||
/* refresh the list to mark plugin active */ | /* refresh the list to mark plugin active */ | |||
gtkui_create_plug_array(); | gtkui_create_plug_array(); | |||
return ret; | ||||
} | } | |||
/* | ||||
* callback when plugin is double clicked in the treeview | ||||
*/ | ||||
static void gtkui_select_plugin_treeview(GtkTreeView *treeview, | ||||
GtkTreePath *path, GtkTreeViewColumn *column, gpointer data) | ||||
{ | ||||
GtkTreeIter iter; | ||||
GtkTreeModel *model; | ||||
GtkTreeSelection *selection; | ||||
gchar *plugin; | ||||
(void) path; | ||||
(void) column; | ||||
(void) data; | ||||
model = gtk_tree_view_get_model(treeview); | ||||
selection = gtk_tree_view_get_selection(treeview); | ||||
if (gtk_tree_selection_get_selected(selection, &model, &iter)) { | ||||
gtk_tree_model_get (model, &iter, 1, &plugin, -1); | ||||
} else | ||||
return; /* nothing is selected */ | ||||
gtkui_select_plugin(plugin); | ||||
} | ||||
/* | ||||
* check if plugins have been supplied on the CLI | ||||
* and try to start all provided plugins | ||||
*/ | ||||
gboolean gtkui_plugins_autostart(gpointer data) | ||||
{ | ||||
struct plugin_list *plugin, *tmp; | ||||
(void) data; | ||||
DEBUG_MSG("gtkui_plugins_autostart()"); | ||||
/* 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 extists */ | ||||
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 { | ||||
/*not we can try to start the plugin */ | ||||
plugin->exists = true; | ||||
if (gtkui_select_plugin(plugin->name) != PLUGIN_RUNNING) { | ||||
USER_MSG("Plugin '%s' can not be started - skipping\n\n", | ||||
plugin->name); | ||||
} | ||||
} | ||||
} | ||||
} | ||||
return FALSE; | ||||
} | ||||
gboolean gtkui_refresh_plugin_list(gpointer data) | gboolean gtkui_refresh_plugin_list(gpointer data) | |||
{ | { | |||
/* avoid warning */ | /* avoid warning */ | |||
(void)data; | (void)data; | |||
DEBUG_MSG("gtk_refresh_plugin_list"); | DEBUG_MSG("gtk_refresh_plugin_list"); | |||
/* refresh the list to mark plugin active */ | /* refresh the list to mark plugin active */ | |||
gtkui_create_plug_array(); | gtkui_create_plug_array(); | |||
End of changes. 12 change blocks. | ||||
23 lines changed or deleted | 79 lines changed or added |