Wireshark-dev: [Wireshark-dev] WSLUA improvement (ProtoField.bool extension)

From: Tamás Regõs <Tamas.Regos@xxxxxxxxxxxx>
Date: Mon, 19 Apr 2010 22:58:16 +0800
Hello,

I'd like to introduce a WSLUA improvement.

The existing ProtoField.bool looks like the following:
ProtoField.bool(abbr, [name], [desc])

But checking any protocol dissector with bool protofield, it can be seen that in C code we have more options than thru the WSLUA interface.
E.g.: {&hf_gtp_qos_sig_ind,{"Signalling Indication", "gtp.sig_ind", FT_BOOLEAN, 8, TFS(&gtp_sig_ind), GTP_EXT_QOS_SIG_IND_MASK, NULL, HFILL}},

So I've extended ProtoField.bool to have more options like this:
ProtoField.bool(abbr, [name], [bitfield], [true_false_string], [mask], [desc])

The required modifications are attached in .diff patch files. All of them has some extra reformatting (unnecessary white space removals) too.
The following file revisions were the latest one in SVN (under trunk).


wslua.diff (for rev 31716)
----------
1 main change in typedef struct _wslua_field_t
- value_string* vs;
+ const void* vs; 


wslua_tree.diff (for rev 31401)
---------------
1 main change which is actually a bug and it is not strictly related to this improvement.

case FT_BOOLEAN:
- item = proto_tree_add_boolean(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(guint32)lua_toboolean(L,1));
+ item = proto_tree_add_boolean(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(guint32)luaL_checknumber(L,1)); 

lua_toboolean <-> luaL_checknumber
This must be checknumber, otherwise with lua_boolean we mask the input octet to 1 bit...


wslua_proto.diff (for rev 32320)
----------------
This has the most changes.

Changes in static const struct base_display_string_t base_displays[]
New function: static true_false_string* true_false_string_from_table(lua_State* L, int idx)
Changes in WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L)
New function: static int ProtoField_boolean(lua_State* L, enum ftenum type)
New definition: #define PROTOFIELD_BOOL(lower,FT) static int ProtoField_##lower(lua_State* L) { return ProtoField_boolean(L,FT); } 
New definition: PROTOFIELD_BOOL(bool,FT_BOOLEAN)
Changes in WSLUA_METAMETHOD ProtoField_tostring(lua_State* L)


An example:
Old: ProtoField.bool("proto.sig_ind", "Signalling Indication", "Signalling Indication")
New: ProtoField.bool("proto.sig_ind", "Signalling Indication", 8, gtp_sig_ind, QOS_SIG_IND_MASK, "Signalling Indication")
Where
  QOS_SIG_IND_MASK = 0x10
  gtp_sig_ind = {
      "Optimised for signalling traffic", -- if true; index 1 is hardcoded in wslua_proto.c
      "Not optimised for signalling traffic" -- if false; index 2 is hardcoded in wslua_proto.c
  }


If these changes will be committed/approved then the Wireshark's Lua API Reference Manual should be also updated like this:
http://www.wireshark.org/docs/wsug_html_chunked/wsluarm_modules.html

11.4.6.6.24. ProtoField.bool(abbr, [name], [bitfield], [true_false_string], [mask], [desc])

abbr
    Abbreviated name of the field (the string used in filters)

name (optional)
    Actual name of the field (the string that appears in the tree)

bitfield (optional)
    Number of bits in the field containing the bitfield (e.g.: BASE_NONE, 8, 16, 24, 32, 64)

true_false_string (optional)
    A table containing the text that corresponds to true and false values

mask (optional)
    Integer mask of this field

desc (optional)
    Description of the field


Any comment? :)

Can we map these changes to trunk-1.2 too (to have it in 1.2.8)?

I haven't created any bug reports for these yet.


Regards,
Tamas

Attachment: wslua.diff
Description: wslua.diff

Attachment: wslua_proto.diff
Description: wslua_proto.diff

Attachment: wslua_tree.diff
Description: wslua_tree.diff

Attachment: wslua-protofield.bool.zip
Description: wslua-protofield.bool.zip