diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2015-11-14 22:29:32 +0100 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2015-11-15 18:33:16 +0000 |
commit | e6b5f015e219f3968897adba0d6440945ff45b8e (patch) | |
tree | a15df32dfa72ecd1931a0f305a87410c585ad96d /epan/wslua | |
parent | 82bd3cc9eb49c886a1b6ff1ad0aa3be096bd8aec (diff) |
Lua: Added support for ProtoField framenum type.
Change-Id: I1d4cddd4026f08416005f2b3212536b3984d1a8d
Reviewed-on: https://code.wireshark.org/review/11834
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'epan/wslua')
-rwxr-xr-x | epan/wslua/make-init-lua.pl | 10 | ||||
-rw-r--r-- | epan/wslua/template-init.lua | 3 | ||||
-rw-r--r-- | epan/wslua/wslua_proto_field.c | 30 |
3 files changed, 38 insertions, 5 deletions
diff --git a/epan/wslua/make-init-lua.pl b/epan/wslua/make-init-lua.pl index d1d55badbb..afebcc5b3f 100755 --- a/epan/wslua/make-init-lua.pl +++ b/epan/wslua/make-init-lua.pl @@ -35,6 +35,7 @@ my $wtap_filetypes_table = ''; my $wtap_tsprecs_table = ''; my $wtap_commenttypes_table = ''; my $ft_types_table = ''; +my $frametypes_table = ''; my $wtap_rec_types_table = ''; my $wtap_presence_flags_table = ''; my $bases_table = ''; @@ -51,6 +52,7 @@ my %replacements = %{{ WTAP_TSPRECS => \$wtap_tsprecs_table, WTAP_COMMENTTYPES => \$wtap_commenttypes_table, FT_TYPES => \$ft_types_table, + FT_FRAME_TYPES => \$frametypes_table, WTAP_REC_TYPES => \$wtap_rec_types_table, WTAP_PRESENCE_FLAGS => \$wtap_presence_flags_table, BASES => \$bases_table, @@ -135,12 +137,17 @@ $wtap_presence_flags_table =~ s/\n$/\n}\n/msi; # $ft_types_table = " -- Field Types\nftypes = {\n"; +$frametypes_table = " -- Field Type FRAMENUM Types\nframetype = {\n"; my $ftype_num = 0; +my $frametypes_num = 0; open FTYPES_H, "< $WSROOT/epan/ftypes/ftypes.h" or die "cannot open '$WSROOT/epan/ftypes/ftypes.h': $!"; while(<FTYPES_H>) { - if ( /^\s+FT_([A-Z0-9a-z_]+)\s*,/ ) { + if ( /^\s+FT_FRAMENUM_([A-Z0-9a-z_]+)\s*,/ ) { + $frametypes_table .= "\t[\"$1\"] = $frametypes_num,\n"; + $frametypes_num++; + } elsif ( /^\s+FT_([A-Z0-9a-z_]+)\s*,/ ) { $ft_types_table .= "\t[\"$1\"] = $ftype_num,\n"; $ftype_num++; } @@ -148,6 +155,7 @@ while(<FTYPES_H>) { close FTYPES_H; $ft_types_table =~ s/,\n$/\n}\n/msi; +$frametypes_table =~ s/,\n$/\n}\n/msi; # # Extract values from epan/proto.h: diff --git a/epan/wslua/template-init.lua b/epan/wslua/template-init.lua index 91ed1d5504..4850ccb4d1 100644 --- a/epan/wslua/template-init.lua +++ b/epan/wslua/template-init.lua @@ -119,6 +119,9 @@ end -- %FT_TYPES% +-- the following table is since 2.0 +-- %FT_FRAME_TYPES% + -- the following table is since 1.12 -- %WTAP_REC_TYPES% diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c index 212ccc2e31..97c4ea8f30 100644 --- a/epan/wslua/wslua_proto_field.c +++ b/epan/wslua/wslua_proto_field.c @@ -315,7 +315,8 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { `ftypes.SYSTEM_ID`, `ftypes.EUI64` or `ftypes.NONE`. */ #define WSLUA_OPTARG_ProtoField_new_VALUESTRING 4 /* A table containing the text that - corresponds to the values. */ + corresponds to the values, or one of `frametype.NONE`, `frametype.REQUEST`, `frametype.RESPONSE`, + `frametype.ACK` or `frametype.DUP_ACK` if field type is ftypes.FRAMENUM. */ #define WSLUA_OPTARG_ProtoField_new_BASE 5 /* The representation, one of: `base.NONE`, `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, or `base.HEX_DEC`. */ @@ -327,6 +328,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { const gchar* name = luaL_checkstring(L,WSLUA_ARG_ProtoField_new_NAME); const gchar* abbr = NULL; enum ftenum type; + enum ft_framenum_type framenum_type = FT_FRAMENUM_NONE; value_string *vs32 = NULL; val64_string *vs64 = NULL; true_false_string *tfs = NULL; @@ -358,6 +360,13 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { WSLUA_OPTARG_ERROR(ProtoField_new,MASK,"FRAMENUM can not have a bitmask"); return 0; } + if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING && !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) { + framenum_type = (enum ft_framenum_type) luaL_checkinteger(L, 4); + if (framenum_type >= FT_FRAMENUM_NUM_TYPES) { + WSLUA_OPTARG_ERROR(ProtoField_new,VALUESTRING,"Invalid frametype"); + return 0; + } + } break; case FT_UINT8: case FT_UINT16: @@ -477,6 +486,8 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Indicate that we are using val64_string */ f->base |= BASE_VAL64_STRING; f->vs = VALS(vs64); + } else if (framenum_type) { + f->vs = FRAMENUM_TYPE(framenum_type); } else { f->vs = NULL; } @@ -498,13 +509,20 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { const gchar* name = luaL_optstring(L,2,abbr); unsigned default_base = (type == FT_FRAMENUM) ? BASE_NONE : BASE_DEC; unsigned base = (unsigned)luaL_optinteger(L, 3, default_base); + enum ft_framenum_type framenum_type = FT_FRAMENUM_NONE; value_string* vs32 = NULL; val64_string* vs64 = NULL; guint32 mask = wslua_optguint32(L,5,0); const gchar* blob = luaL_optstring(L,6,NULL); if (lua_gettop(L) > 3) { - if (type == FT_UINT64 || type == FT_INT64) { + if (type == FT_FRAMENUM) { + framenum_type = (enum ft_framenum_type) luaL_checkinteger(L, 4); + if (framenum_type >= FT_FRAMENUM_NUM_TYPES) { + luaL_argerror(L, 4, "Invalid frametype"); + return 0; + } + } else if (type == FT_UINT64 || type == FT_INT64) { vs64 = val64_string_from_table(L,4); } else { vs32 = value_string_from_table(L,4); @@ -538,8 +556,12 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* Indicate that we are using val64_string */ f->base |= BASE_VAL64_STRING; f->vs = VALS(vs64); - } else { + } else if (vs32) { f->vs = VALS(vs32); + } else if (framenum_type) { + f->vs = FRAMENUM_TYPE(framenum_type); + } else { + f->vs = NULL; } f->mask = mask; if (blob && strcmp(blob, f->name) != 0) { @@ -648,7 +670,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_ARG_Protofield_framenum_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_Protofield_framenum_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_Protofield_framenum_BASE Only `base.NONE` is supported for framenum. */ -/* WSLUA_OPTARG_Protofield_framenum_VALUESTRING A table containing the text that corresponds to the values. */ +/* WSLUA_OPTARG_Protofield_framenum_FRAMETYPE One of `frametype.NONE`, `frametype.REQUEST`, `frametype.RESPONSE`, `frametype.ACK` or `frametype.DUP_ACK`. */ /* WSLUA_OPTARG_Protofield_framenum_MASK Integer mask of this field, which must be 0 for framenum. */ /* WSLUA_OPTARG_Protofield_framenum_DESC Description of the field. */ /* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ |