diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2006-03-11 22:05:40 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2006-03-11 22:05:40 +0000 |
commit | b3a173664b53df47095cc23a7b3d589f33e88be8 (patch) | |
tree | 8740d1c2538f6fecce65964f08309ccd3536a1de | |
parent | 297ed538fc77cf282f17fba412fcad815fae6feb (diff) | |
download | wireshark-b3a173664b53df47095cc23a7b3d589f33e88be8.tar.gz |
Protocols register OK.
svn path=/trunk/; revision=17594
-rw-r--r-- | plugins/lua/elua.c | 25 | ||||
-rw-r--r-- | plugins/lua/elua.h | 13 | ||||
-rw-r--r-- | plugins/lua/elua_makereg.pl | 12 | ||||
-rw-r--r-- | plugins/lua/elua_proto.c | 83 |
4 files changed, 82 insertions, 51 deletions
diff --git a/plugins/lua/elua.c b/plugins/lua/elua.c index dd3bbf6516..b22e965279 100644 --- a/plugins/lua/elua.c +++ b/plugins/lua/elua.c @@ -58,7 +58,7 @@ static int elua_not_print(lua_State* L) { void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) { lua_pinfo = pinfo; lua_tvb = tvb; - + lua_tree = ep_alloc(sizeof(struct _eth_treeitem)); lua_tree->tree = tree; lua_tree->item = proto_tree_add_text(tree,tvb,0,0,"lua fake item"); @@ -70,14 +70,14 @@ void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) { */ lua_settop(L,0); - + lua_rawgeti(L, LUA_REGISTRYINDEX, lua_dissectors_table_ref); lua_pushstring(L, pinfo->current_proto); lua_gettable(L, -2); - + lua_remove(L,1); - + if (lua_isfunction(L,1)) { @@ -87,7 +87,7 @@ void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) { if ( lua_pcall(L,3,0,0) ) { const gchar* error = lua_tostring(L,-1); - + proto_item* pi = proto_tree_add_text(tree,tvb,0,0,"Lua Error: %s",error); expert_add_info_format(pinfo, pi, PI_DEBUG, PI_ERROR ,"Lua Error"); } @@ -101,12 +101,12 @@ void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) { clear_outstanding_tvbs(); clear_outstanding_pinfos(); clear_outstanding_trees(); - + lua_pinfo = NULL; lua_tree = NULL; lua_tvb = NULL; - + } static void iter_table_and_call(lua_State* LS, int env, const gchar* table_name, lua_CFunction error_handler) { @@ -155,9 +155,7 @@ static int init_error_handler(lua_State* L) { static void init_lua(void) { if ( ! lua_initialized ) { - lua_prime_all_fields(NULL); - lua_initialized = TRUE; } @@ -219,6 +217,11 @@ static void basic_logger(const gchar *log_domain _U_, fputs(message,stderr); } +static int elua_panic(lua_State* LS) { + g_error("LUA PANIC: %s",lua_tostring(LS,-1)); + return 0; +} + void register_lua(void) { const gchar* filename; const funnel_ops_t* ops = funnel_get_funnel_ops(); @@ -234,6 +237,8 @@ void register_lua(void) { ELUA_INIT(L); + lua_atpanic(L,elua_panic); + /* print has been changed to yield an error if used */ lua_pushstring(L, "print"); lua_pushcfunction(L, elua_not_print); @@ -310,6 +315,8 @@ void register_lua(void) { lua_data_handle = find_dissector("data"); lua_malformed = proto_get_id_by_filter_name("malformed"); + Proto_commit(L); + return; } diff --git a/plugins/lua/elua.h b/plugins/lua/elua.h index fa755d67c3..2ddf7113d5 100644 --- a/plugins/lua/elua.h +++ b/plugins/lua/elua.h @@ -289,20 +289,15 @@ extern int lua_dissectors_table_ref; ELUA_DECLARE_CLASSES() ELUA_DECLARE_FUNCTIONS() -extern void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree); -extern int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const void *data _U_); -extern void lua_tap_reset(void *tapdata); -extern void lua_tap_draw(void *tapdata); - extern const gchar* lua_shiftstring(lua_State* L,int idx); +extern void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree); -extern int lua_register_menu(lua_State* L); -extern int lua_new_dialog(lua_State* L); -extern int lua_gui_enabled(lua_State* L); extern void proto_register_lua(void); extern GString* lua_register_all_taps(void); extern void lua_prime_all_fields(proto_tree* tree); +extern int Proto_commit(lua_State* L); + extern void* push_Tvb(lua_State* L, Tvb tvb); extern void clear_outstanding_tvbs(void); @@ -312,4 +307,6 @@ extern void clear_outstanding_pinfos(void); extern void* push_TreeItem(lua_State* L, TreeItem ti); extern void clear_outstanding_trees(void); +extern void elua_print_stack(char* s, lua_State* L); + #endif diff --git a/plugins/lua/elua_makereg.pl b/plugins/lua/elua_makereg.pl index f06f63fceb..a7807fcde7 100644 --- a/plugins/lua/elua_makereg.pl +++ b/plugins/lua/elua_makereg.pl @@ -35,18 +35,18 @@ while (<>) { print "/* This file is automatically genrated by elua_makereg.pl do not edit */\n\n"; -print "#define ELUA_REGISTER_CLASSES() { \\\n"; -for (@classes) { - print "\t${_}_register(L);\\\n" -} -print "}\n\n"; - print "#define ELUA_DECLARE_CLASSES() \\\n"; for (@classes) { print "\tELUA_CLASS_DECLARE($_);\\\n" } print "\n\n"; +print "#define ELUA_REGISTER_CLASSES() { \\\n"; +for (@classes) { + print "\t${_}_register(L);\\\n" +} +print "}\n\n"; + print "#define ELUA_DECLARE_FUNCTIONS() \\\n"; for (@functions) { print "\tELUA_FUNCTION elua_$_(lua_State* L);\\\n" diff --git a/plugins/lua/elua_proto.c b/plugins/lua/elua_proto.c index 41b84b7661..83f525eeb5 100644 --- a/plugins/lua/elua_proto.c +++ b/plugins/lua/elua_proto.c @@ -462,7 +462,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { f->hfid = -2; f->ett = -1; f->name = g_strdup(name); - f->abbr = NULL; + f->abbr = g_strdup(abbr); f->type = type; f->vs = vs; f->base = base; @@ -514,7 +514,7 @@ static int ProtoField_other(lua_State* L,enum ftenum type) { f->hfid = -2; f->ett = -1; f->name = g_strdup(name); - f->abbr = NULL; + f->abbr = g_strdup(abbr); f->type = type; f->vs = NULL; f->base = ( type == FT_FLOAT || type == FT_DOUBLE) ? BASE_DEC : BASE_NONE; @@ -646,7 +646,7 @@ ELUA_CLASS_DEFINE(Proto,NOP) other purposes. */ -static int protocols_table_ref = 0; +static int protocols_table_ref = LUA_NOREF; ELUA_CONSTRUCTOR Proto_new(lua_State* L) { #define ELUA_ARG_Proto_new_NAME 1 /* The name of the protocol */ @@ -669,7 +669,7 @@ ELUA_CONSTRUCTOR Proto_new(lua_State* L) { proto->name = loname; proto->desc = g_strdup(desc); - proto->hfid = proto_register_protocol(proto->desc,loname,hiname); + proto->hfid = proto_register_protocol(proto->desc,hiname,loname); proto->ett = -1; lua_newtable (L); @@ -685,14 +685,16 @@ ELUA_CONSTRUCTOR Proto_new(lua_State* L) { proto->prefs_module = NULL; proto->handle = NULL; - if (! protocols_table_ref) { + if ( protocols_table_ref == LUA_NOREF) { lua_newtable(L); protocols_table_ref = luaL_ref(L, LUA_REGISTRYINDEX); } lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref); - pushProto(L,proto); + lua_pushstring(L,loname); + pushProto(L,proto); + lua_settable(L, -3); pushProto(L,proto); @@ -813,32 +815,43 @@ static int Proto_get_fields(lua_State* L) { return 1; } +void elua_print_stack(char* s, lua_State* L) { + int i; + + for (i=1;i<=lua_gettop(L);i++) { + printf("%s-%i: %s\n",s,i,lua_typename (L,lua_type(L, i))); + } + printf("\n"); +} + static int Proto_set_fields(lua_State* L) { - int i = 0; Proto proto = toProto(L,1); - /* "fields" string in pos 2 */ - /* assigned value in pos 3 */ - lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields); /* fields table in pos 4 */ - lua_replace(L,2); /* fields table now in pos 2 */ - - for (lua_pushnil(L); lua_next(L, 2); lua_pop(L, 1)) { i++; } /* find last index of table */ - - if( lua_istable(L,3)) { +#define FIELDS_TABLE 2 +#define NEW_TABLE 3 +#define NEW_FIELD 3 + + lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields); + lua_replace(L,FIELDS_TABLE); - for (lua_pushnil(L); lua_next(L, 3); lua_pop(L, 1)) { - if (! isProtoField(L,-1)) { + + if( lua_istable(L,NEW_TABLE)) { + for (lua_pushnil(L); lua_next(L, NEW_TABLE); ) { + if (isProtoField(L,5)) { + luaL_ref(L,FIELDS_TABLE); + } else if (! lua_isnil(L,5) ) { return luaL_error(L,"only ProtoFields should be in the table"); } - lua_rawseti(L,4,i++); } - } else if (isProtoField(L,3)){ - lua_pushvalue(L, 3); - lua_rawseti(L,4,i++); + } else if (isProtoField(L,NEW_FIELD)){ + lua_pushvalue(L, NEW_FIELD); + luaL_ref(L,FIELDS_TABLE); + } else { return luaL_error(L,"either a ProtoField or an array of protofields"); } lua_pushvalue(L, 3); + return 1; } @@ -937,17 +950,28 @@ int Proto_register(lua_State* L) { int Proto_commit(lua_State* L) { lua_settop(L,0); lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref); + elua_print_stack("Proto_commit 0 ",L); - for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) { + for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 2)) { GArray* hfa = g_array_new(TRUE,TRUE,sizeof(hf_register_info)); GArray* etta = g_array_new(TRUE,TRUE,sizeof(gint*)); - Proto proto = checkProto(L,-1); + Proto proto; + const gchar* proto_name; + elua_print_stack("Proto_commit 1 ",L); + proto_name = lua_tostring(L,2); + proto = checkProto(L,3); + + elua_print_stack("Proto_commit 2 ",L); lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields); + + elua_print_stack("Proto_commit 3 ",L); - for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) { - ProtoField f = checkProtoField(L,-1); + for (lua_pushnil(L); lua_next(L, 4); lua_pop(L, 1)) { + ProtoField f = checkProtoField(L,6); hf_register_info hfri = { &(f->hfid), {f->name,f->abbr,f->type,f->base,VALS(f->vs),f->mask,f->blob,HFILL}}; + gint* ettp = &(f->ett); + elua_print_stack("Proto_commit 4.2 ",L); if (f->hfid != -2) { return luaL_error(L,"fields can be registered only once"); @@ -955,9 +979,7 @@ int Proto_commit(lua_State* L) { f->hfid = -1; g_array_append_val(hfa,hfri); - - g_array_set_size(etta,etta->len+1); - g_array_index(etta,gint*,etta->len) = &(f->ett); + g_array_append_val(etta,ettp); } proto_register_field_array(proto->hfid,(hf_register_info*)hfa->data,hfa->len); @@ -965,17 +987,22 @@ int Proto_commit(lua_State* L) { g_array_free(hfa,FALSE); g_array_free(etta,FALSE); + + elua_print_stack("Proto_commit 5 ",L); + } return 0; } + ELUA_CLASS_DEFINE(Dissector,NOP) /* A refererence to a dissector, used to call a dissector against a packet or a part of it. */ + ELUA_CONSTRUCTOR Dissector_get (lua_State *L) { /* * Obtains a dissector reference by name |