diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2015-01-03 19:27:59 -0500 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2015-01-04 09:07:02 +0000 |
commit | 7c9d6ff73a40e3ebdf00650283ea87a66d1312ee (patch) | |
tree | bc55feeb475c907961fe8013c53374eb077856c0 /epan | |
parent | 2ef85f5cda2d3289455a314a8bc16f25ef26850a (diff) |
Lua: replace proto_tree_add_text calls
Replace proto_tree_add_text() calls in Lua API code, to use Lua-specific hfinfo items.
Bug: 10828
Change-Id: I9b5899106502a9bdbc748b5ec0f27b787d374562
Reviewed-on: https://code.wireshark.org/review/6296
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/wslua/init_wslua.c | 24 | ||||
-rw-r--r-- | epan/wslua/wslua.h | 1 | ||||
-rw-r--r-- | epan/wslua/wslua_tree.c | 9 |
3 files changed, 31 insertions, 3 deletions
diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c index 3b6d29479f..a70edf795c 100644 --- a/epan/wslua/init_wslua.c +++ b/epan/wslua/init_wslua.c @@ -56,6 +56,10 @@ int lua_dissectors_table_ref = LUA_NOREF; int lua_heur_dissectors_table_ref = LUA_NOREF; static int proto_lua = -1; + +static int hf_wslua_fake = -1; +static int hf_wslua_text = -1; + static expert_field ei_lua_error = EI_INIT; static expert_field ei_lua_proto_checksum_comment = EI_INIT; @@ -143,6 +147,11 @@ static int wslua_not_register_menu(lua_State* LS) { return 0; } +/* a getter for wslua_tree.c's TreeItem_add_item_any() to use */ +int get_hf_wslua_text(void) { + return hf_wslua_text; +} + int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_) { int consumed_bytes = tvb_captured_length(tvb); lua_pinfo = pinfo; @@ -150,7 +159,7 @@ int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data lua_tree = (struct _wslua_treeitem *)g_malloc(sizeof(struct _wslua_treeitem)); lua_tree->tree = tree; - lua_tree->item = proto_tree_add_text(tree,tvb,0,0,"lua fake item"); + lua_tree->item = proto_tree_add_item(tree, hf_wslua_fake, tvb, 0, 0, ENC_NA); lua_tree->expired = FALSE; PROTO_ITEM_SET_HIDDEN(lua_tree->item); @@ -268,7 +277,7 @@ gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, v lua_tree = (struct _wslua_treeitem *)g_malloc(sizeof(struct _wslua_treeitem)); lua_tree->tree = tree; - lua_tree->item = proto_tree_add_text(tree,tvb,0,0,"lua fake item"); + lua_tree->item = proto_tree_add_item(tree, hf_wslua_fake, tvb, 0, 0, ENC_NA); lua_tree->expired = FALSE; PROTO_ITEM_SET_HIDDEN(lua_tree->item); @@ -667,6 +676,16 @@ int wslua_init(register_cb cb, gpointer client_data) { expert_module_t* expert_lua; int file_count = 1; + static hf_register_info hf[] = { + { &hf_wslua_fake, + { "Wireshark Lua fake item", "_ws.lua.fake", + FT_NONE, BASE_NONE, NULL, 0x0, + "Fake internal item for Wireshark Lua", HFILL }}, + { &hf_wslua_text, + { "Wireshark Lua text", "_ws.lua.text", + FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }}, + }; + static ei_register_info ei[] = { /* the following are created so we can continue to support the TreeItem_add_expert_info() function to Lua scripts. That function doesn't know what registered protocol to use, @@ -766,6 +785,7 @@ int wslua_init(register_cb cb, gpointer client_data) { WSLUA_INIT(L); proto_lua = proto_register_protocol("Lua Dissection", "Lua Dissection", "_ws.lua"); + proto_register_field_array(proto_lua, hf, array_length(hf)); expert_lua = expert_register_protocol(proto_lua); expert_register_field_array(expert_lua, ei, array_length(ei)); diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index bf0d47f7fa..9971697914 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -702,6 +702,7 @@ extern void clear_outstanding_Column(void); extern void clear_outstanding_Columns(void); extern void clear_outstanding_PrivateTable(void); +extern int get_hf_wslua_text(void); extern TreeItem* push_TreeItem(lua_State* L, TreeItem ti); extern void clear_outstanding_TreeItem(void); diff --git a/epan/wslua/wslua_tree.c b/epan/wslua/wslua_tree.c index 193727d1cc..5d8aac895b 100644 --- a/epan/wslua/wslua_tree.c +++ b/epan/wslua/wslua_tree.c @@ -396,7 +396,14 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { } else { if (lua_gettop(L)) { const gchar* s = lua_tostring(L,1); - item = proto_tree_add_text(tree_item->tree, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len,"%s",s); + const int hf = get_hf_wslua_text(); + if (hf > -1) { + /* use proto_tree_add_none_format() instead? */ + item = proto_tree_add_item(tree_item->tree, hf, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, ENC_NA); + proto_item_set_text(item, "%s", s); + } else { + luaL_error(L,"Internal error: hf_wslua_text not registered"); + } lua_remove(L,1); } else { luaL_error(L,"Tree item ProtoField/Protocol handle is invalid (ProtoField/Proto not registered?)"); |