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>
This commit is contained in:
Stig Bjørlykke 2015-11-14 22:29:32 +01:00
parent 82bd3cc9eb
commit e6b5f015e2
5 changed files with 46 additions and 7 deletions

View File

@ -102,7 +102,8 @@ enum ft_framenum_type {
FT_FRAMENUM_REQUEST,
FT_FRAMENUM_RESPONSE,
FT_FRAMENUM_ACK,
FT_FRAMENUM_DUP_ACK
FT_FRAMENUM_DUP_ACK,
FT_FRAMENUM_NUM_TYPES /* last item number plus one */
};
typedef enum ft_framenum_type ft_framenum_type_t;

View File

@ -5851,6 +5851,9 @@ free_deregistered_field (gpointer data, gpointer user_data _U_)
if (hfi->strings) {
switch (hfi->type) {
case FT_FRAMENUM:
/* This is just an integer represented as a pointer */
break;
case FT_PROTOCOL: {
protocol_t *protocol = (protocol_t *)hfi->strings;
g_free((gchar *)protocol->short_name);
@ -5881,7 +5884,9 @@ free_deregistered_field (gpointer data, gpointer user_data _U_)
break;
}
}
g_free((void *)hfi->strings);
if (hfi->type != FT_FRAMENUM) {
g_free((void *)hfi->strings);
}
}
if (hfi->parent == -1)

View File

@ -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:

View File

@ -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%

View File

@ -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. */