From 2e7726b3ffd6ec3d87742219ad944645ebc24edb Mon Sep 17 00:00:00 2001 From: Luis Ontanon Date: Wed, 27 Sep 2006 17:12:42 +0000 Subject: [PATCH] * rename REGISTER_STAT_GROUP_E -> register_stat_group_t * Add a "Tools" menu * allow wslua's register_menu to register menu items into more menus svn path=/trunk/; revision=19338 --- epan/funnel.c | 4 ++-- epan/funnel.h | 4 ++-- epan/wslua/make-init-lua.pl | 19 ++++++++++++++++++ epan/wslua/template-init.lua | 22 ++++++++++----------- epan/wslua/wslua_gui.c | 37 +++++++++++++++++------------------- gtk/funnel_stat.c | 2 +- gtk/gui_stat_menu.h | 2 +- gtk/menu.c | 13 +++++++++++-- gtk/tap_dfilter_dlg.c | 2 +- stat_menu.h | 5 +++-- tap-funnel.c | 27 ++++++++++++++++++++++++-- tap_dfilter_dlg.h | 2 +- 12 files changed, 94 insertions(+), 45 deletions(-) diff --git a/epan/funnel.c b/epan/funnel.c index 185fe3dc20..17ec6387ae 100644 --- a/epan/funnel.c +++ b/epan/funnel.c @@ -30,7 +30,7 @@ typedef struct _funnel_menu_t { const char *name; - REGISTER_STAT_GROUP_E group; + register_stat_group_t group; void (*callback)(gpointer); gpointer callback_data; gboolean retap; @@ -44,7 +44,7 @@ const funnel_ops_t* funnel_get_funnel_ops() { return ops; } void funnel_set_funnel_ops(const funnel_ops_t* o) { ops = o; } void funnel_register_menu(const char *name, - REGISTER_STAT_GROUP_E group, + register_stat_group_t group, void (*callback)(gpointer), gpointer callback_data, gboolean retap) { diff --git a/epan/funnel.h b/epan/funnel.h index 16508af124..3cd7eb22ea 100644 --- a/epan/funnel.h +++ b/epan/funnel.h @@ -91,14 +91,14 @@ extern void funnel_set_funnel_ops(const funnel_ops_t*); extern void funnel_register_menu(const char *name, - REGISTER_STAT_GROUP_E group, + register_stat_group_t group, void (*callback)(gpointer), gpointer callback_data, gboolean retap); typedef void (*funnel_registration_cb_t)(const char *name, - REGISTER_STAT_GROUP_E group, + register_stat_group_t group, void (*callback)(gpointer), gpointer callback_data, gboolean retap); diff --git a/epan/wslua/make-init-lua.pl b/epan/wslua/make-init-lua.pl index 23fbe3601b..06dd7d4190 100755 --- a/epan/wslua/make-init-lua.pl +++ b/epan/wslua/make-init-lua.pl @@ -34,12 +34,14 @@ my $wtap_encaps_table = ''; my $ft_types_table = ''; my $bases_table = ''; my $expert_pi = ''; +my $menu_groups = ''; my %replacements = %{{ WTAP_ENCAPS => \$wtap_encaps_table, FT_TYPES => \$ft_types_table, BASES => \$bases_table, EXPERT => \$expert_pi, + MENU_GROUPS => \$menu_groups, }}; @@ -110,6 +112,23 @@ while() { } close PROTO_H; +# register_stat_group_t + + +$menu_groups .= "-- menu groups for register_menu \n"; +my $menu_i = 0; + +open STAT_MENU, "< $WSROOT/stat_menu.h"; +while() { + if (/REGISTER_([A-Z]+)_GROUP_([A-Z]+)/) { + $menu_groups .= "MENU_$1_$2 = $menu_i\n"; + $menu_groups =~ s/_NONE//; + $menu_i++; + } +} +close STAT_MENU; + + $bases_table .= "}\n\n"; $expert_pi .= "\n\n"; diff --git a/epan/wslua/template-init.lua b/epan/wslua/template-init.lua index 76d8c76543..0541f74148 100644 --- a/epan/wslua/template-init.lua +++ b/epan/wslua/template-init.lua @@ -51,8 +51,17 @@ end -- have print() call info() instead. print = info +-- %WTAP_ENCAPS% --- a Console to execute commands in lua +-- %FT_TYPES% + +-- %BASES% + +-- %EXPERT% + +-- %MENU_GROUPS% + +-- Console to execute commands in lua function wslua_console() local w = TextWindow.new("Lua Console") w:set_editable(TRUE) @@ -73,14 +82,5 @@ function wslua_console() w:add_button("Evaluate",eval) end -register_menu("Lua Console",wslua_console) - - --- %WTAP_ENCAPS% - --- %FT_TYPES% - --- %BASES% - --- %EXPERT% +register_menu("Lua Console",wslua_console,MENU_TOOLS) diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c index 9c7c563913..bd174041b8 100644 --- a/epan/wslua/wslua_gui.c +++ b/epan/wslua/wslua_gui.c @@ -1,5 +1,5 @@ /* - * lua_gui.c + * wslua_gui.c * * (c) 2006, Luis E. Garcia Ontanon * @@ -31,7 +31,6 @@ static const funnel_ops_t* ops = NULL; struct _lua_menu_data { lua_State* L; int cb_ref; - int data_ref; }; static int menu_cb_error_handler(lua_State* L) { @@ -50,9 +49,9 @@ void lua_menu_callback(gpointer data) { lua_pushcfunction(md->L,menu_cb_error_handler); lua_rawgeti(md->L, LUA_REGISTRYINDEX, md->cb_ref); - lua_rawgeti(md->L, LUA_REGISTRYINDEX, md->data_ref); - - lua_pcall(md->L,1,0,1); + + /* XXX handle error */ + lua_pcall(md->L,0,0,1); return; } @@ -60,33 +59,31 @@ void lua_menu_callback(gpointer data) { WSLUA_FUNCTION wslua_register_menu(lua_State* L) { /* Register a menu item in the Statistics menu. */ #define WSLUA_ARG_register_menu_NAME 1 /* The name of the menu item. */ #define WSLUA_ARG_register_menu_ACTION 2 /* The function to be called when the menu item is invoked. */ -#define WSLUA_OPTARG_register_menu_USERDATA 3 /* To be passed to the action. */ - +#define WSLUA_ARG_register_menu_GROUP 3 /* The menu group into which the menu item is to be inserted. */ + const gchar* name = luaL_checkstring(L,WSLUA_ARG_register_menu_NAME); struct _lua_menu_data* md; gboolean retap = FALSE; - + register_stat_group_t group = luaL_optnumber(L,WSLUA_ARG_register_menu_GROUP,REGISTER_STAT_GROUP_GENERIC); + + if ( group > REGISTER_TOOLS_GROUP_NONE) + WSLUA_ARG_ERROR(register_menu,GROUP,"must be a defined MENU_* (see init.lua)"); + if(!name) WSLUA_ARG_ERROR(register_menu,NAME,"must be a string"); if (!lua_isfunction(L,WSLUA_ARG_register_menu_ACTION)) WSLUA_ARG_ERROR(register_menu,ACTION,"must be a function"); - + md = g_malloc(sizeof(struct _lua_menu_data)); md->L = L; - - lua_pushvalue(L, 2); - md->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX); - - if ( lua_gettop(L) > 2) { - lua_pushvalue(L, WSLUA_OPTARG_register_menu_USERDATA); - md->data_ref = luaL_ref(L, LUA_REGISTRYINDEX); - } else { - md->data_ref = LUA_NOREF; - } + + lua_pushvalue(L, 2); + md->cb_ref = luaL_ref(L, LUA_REGISTRYINDEX); + lua_remove(L,2); funnel_register_menu(name, - REGISTER_STAT_GROUP_GENERIC, + group, lua_menu_callback, md, retap); diff --git a/gtk/funnel_stat.c b/gtk/funnel_stat.c index 77d13d711c..506a549cd9 100644 --- a/gtk/funnel_stat.c +++ b/gtk/funnel_stat.c @@ -544,7 +544,7 @@ static void our_menu_callback(void* unused _U_, gpointer data) { } static void register_menu_cb(const char *name, - REGISTER_STAT_GROUP_E group, + register_stat_group_t group, void (*callback)(gpointer), gpointer callback_data, gboolean retap) { diff --git a/gtk/gui_stat_menu.h b/gtk/gui_stat_menu.h index 595ed1348e..40124c1d49 100644 --- a/gtk/gui_stat_menu.h +++ b/gtk/gui_stat_menu.h @@ -63,7 +63,7 @@ extern "C" { */ extern void register_stat_menu_item( const char *name, - REGISTER_STAT_GROUP_E group, + register_stat_group_t group, GtkItemFactoryCallback callback, gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *), gboolean (*selected_tree_row_enabled)(field_info *), diff --git a/gtk/menu.c b/gtk/menu.c index fe9e5b2473..3a82105906 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -598,7 +598,8 @@ static GtkItemFactoryEntry menu_items[] = init_conversation_notebook_cb, 0, WIRESHARK_STOCK_CONVERSATIONS), ITEM_FACTORY_STOCK_ENTRY("/Statistics/Endpoints", NULL, init_hostlist_notebook_cb, 0, WIRESHARK_STOCK_ENDPOINTS), - ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/_Tools", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/_Help", NULL, NULL, 0, "", NULL), ITEM_FACTORY_STOCK_ENTRY("/Help/_Contents", "F1", topic_menu_cb, HELP_CONTENT, GTK_STOCK_HELP), ITEM_FACTORY_ENTRY("/Help/_Supported Protocols", NULL, supported_cb, 0, NULL, NULL), #if (GLIB_MAJOR_VERSION >= 2) @@ -914,7 +915,7 @@ static GList * tap_menu_item_add( void register_stat_menu_item( const char *name, - REGISTER_STAT_GROUP_E group, + register_stat_group_t group, GtkItemFactoryCallback callback, gboolean (*selected_packet_enabled)(frame_data *, epan_dissect_t *), gboolean (*selected_tree_row_enabled)(field_info *), @@ -942,6 +943,7 @@ register_stat_menu_item( case(REGISTER_STAT_GROUP_TELEPHONY): toolspath = "/Statistics/"; break; case(REGISTER_STAT_GROUP_NONE): toolspath = "/Statistics/"; break; case(REGISTER_ANALYZE_GROUP_NONE): toolspath = "/Analyze/"; break; + case(REGISTER_TOOLS_GROUP_NONE): toolspath = "/Tools/"; break; default: g_assert(0); toolspath = NULL; @@ -1067,6 +1069,8 @@ static guint merge_tap_menus_layered(GList *node, gint group) { break; case(REGISTER_ANALYZE_GROUP_NONE): break; + case(REGISTER_TOOLS_GROUP_NONE): + break; default: g_assert_not_reached(); } @@ -1139,6 +1143,11 @@ void merge_all_tap_menus(GList *node) { entry->path = "/Analyze/"; /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/ } + if (merge_tap_menus_layered(node, REGISTER_TOOLS_GROUP_NONE)) { + /*gtk_item_factory_create_item(main_menu_factory, entry, NULL, 2);*/ + } + + } diff --git a/gtk/tap_dfilter_dlg.c b/gtk/tap_dfilter_dlg.c index c94ff0a0ae..b6e32505a6 100644 --- a/gtk/tap_dfilter_dlg.c +++ b/gtk/tap_dfilter_dlg.c @@ -71,7 +71,7 @@ tap_dfilter_dlg_cb(GtkWidget *w, gpointer data); */ void register_dfilter_stat(tap_dfilter_dlg *info, const char *name, - REGISTER_STAT_GROUP_E group) + register_stat_group_t group) { char *full_name; diff --git a/stat_menu.h b/stat_menu.h index ec3e6cda36..1d9d0aab79 100644 --- a/stat_menu.h +++ b/stat_menu.h @@ -50,8 +50,9 @@ typedef enum { REGISTER_STAT_GROUP_RESPONSE_TIME, REGISTER_STAT_GROUP_TELEPHONY, /* XXX - split into telephony and VoIP? */ - REGISTER_ANALYZE_GROUP_NONE -} REGISTER_STAT_GROUP_E; + REGISTER_ANALYZE_GROUP_NONE, + REGISTER_TOOLS_GROUP_NONE, +} register_stat_group_t; #ifdef __cplusplus } diff --git a/tap-funnel.c b/tap-funnel.c index 490a558a22..10711afc0c 100644 --- a/tap-funnel.c +++ b/tap-funnel.c @@ -1,6 +1,29 @@ /* * tap-funnel.c - * + * + * EPAN's GUI mini-API + * + * (c) 2006, Luis E. Garcia Ontanon + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -126,7 +149,7 @@ static void init_funnel_cmd(const char *optarg, void* data ) { } static void register_menu_cb(const char *name, - REGISTER_STAT_GROUP_E group _U_, + register_stat_group_t group _U_, void (*callback)(gpointer), gpointer callback_data, gboolean retap _U_) { diff --git a/tap_dfilter_dlg.h b/tap_dfilter_dlg.h index 18a75e982a..43fe396aad 100644 --- a/tap_dfilter_dlg.h +++ b/tap_dfilter_dlg.h @@ -67,7 +67,7 @@ typedef struct _tap_dfilter_dlg { * We register it both as a command-line stat and a menu item stat. */ void register_dfilter_stat(tap_dfilter_dlg *info, const char *name, - REGISTER_STAT_GROUP_E group); + register_stat_group_t group); /* This will update the titles of the dialog windows when we load a new capture file. */ void tap_dfilter_dlg_update (void);