diff options
author | Nardi Ivan <nardi.ivan@gmail.com> | 2021-07-15 14:04:06 +0200 |
---|---|---|
committer | AndersBroman <a.broman58@gmail.com> | 2023-01-04 14:32:23 +0000 |
commit | e6e3a916969eb68713fc7604f5215566813c5162 (patch) | |
tree | de57ffb9ecb480d0858bce7cf3ecc92f35336484 /epan/wslua | |
parent | d4cd1d9d1d78a4e5ce289616628aa7d0685922a0 (diff) |
WSLUA: allow 64 bits bitmask for ProtoField objects
Mask might be specified using a (Lua) number, a string or a UInt64
object.
It is useful to handle 64 bit bitfields.
Diffstat (limited to 'epan/wslua')
-rw-r--r-- | epan/wslua/wslua.h | 3 | ||||
-rw-r--r-- | epan/wslua/wslua_int64.c | 2 | ||||
-rw-r--r-- | epan/wslua/wslua_proto_field.c | 53 |
3 files changed, 40 insertions, 18 deletions
diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index f7bdf09c2d..682dc53061 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -118,7 +118,7 @@ typedef struct _wslua_field_t { enum ftenum type; unsigned base; const void* vs; - guint32 mask; + guint64 mask; } wslua_field_t; typedef struct _wslua_expert_field_t { @@ -771,6 +771,7 @@ extern void Int64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittle extern int Int64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian); extern void UInt64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian); extern int UInt64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian); +extern guint64 getUInt64(lua_State *L, int i); extern Tvb* push_Tvb(lua_State* L, tvbuff_t* tvb); extern int push_wsluaTvb(lua_State* L, Tvb t); diff --git a/epan/wslua/wslua_int64.c b/epan/wslua/wslua_int64.c index 08a9100d11..e540d6d203 100644 --- a/epan/wslua/wslua_int64.c +++ b/epan/wslua/wslua_int64.c @@ -647,7 +647,7 @@ WSLUA_CLASS_DEFINE_BASE(UInt64,NOP,0); */ /* A checkUInt64 but that also auto-converts numbers, strings, and <<lua_class_Int64,`Int64`>> to a guint64. */ -static guint64 getUInt64(lua_State *L, int i) +guint64 getUInt64(lua_State *L, int i) { gchar *end = NULL; (void) end; diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c index 494aa099fe..fa8206e0a0 100644 --- a/epan/wslua/wslua_proto_field.c +++ b/epan/wslua/wslua_proto_field.c @@ -415,6 +415,27 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) { return tfs; } +static guint64 get_mask(lua_State* L, int idx, guint64 default_value) { + guint64 mask = default_value; + + switch(lua_type(L, idx)) { + case LUA_TNUMBER: + mask = (guint64)wslua_optguint32(L, idx, default_value); + break; + case LUA_TSTRING: + case LUA_TUSERDATA: + mask = getUInt64(L,idx); + break; + case LUA_TNIL: + case LUA_TNONE: + break; + default: + luaL_argerror(L,idx,"MASK field must be a number, UInt64 or string"); + break; + } + return mask; +} + static unit_name_string* unit_name_string_from_table(lua_State* L, int idx) { unit_name_string* units; @@ -541,7 +562,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { true_false_string *tfs = NULL; unit_name_string *uns = NULL; unsigned base; - guint32 mask = wslua_optguint32(L, WSLUA_OPTARG_ProtoField_new_MASK, 0x0); + guint64 mask = get_mask(L,WSLUA_OPTARG_ProtoField_new_MASK, 0x0); const gchar *blob = luaL_optstring(L,WSLUA_OPTARG_ProtoField_new_DESCR,NULL); gboolean base_unit_string = FALSE; gboolean base_range_string = FALSE; @@ -808,7 +829,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { range_string* rs32 = NULL; val64_string* vs64 = NULL; unit_name_string* uns = NULL; - guint32 mask = wslua_optguint32(L,5,0); + guint64 mask = get_mask(L,5,0); const gchar* blob = luaL_optstring(L,6,NULL); gboolean base_unit_string = FALSE; gboolean base_range_string = FALSE; @@ -948,7 +969,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint8_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint8_BASE One of `base.DEC`, `base.HEX` or `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING` or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint8_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint8_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint8_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint8_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -957,7 +978,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint16_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint16_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING` or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint16_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint16_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint16_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint16_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -966,7 +987,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint24_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint24_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint24_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint24_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint24_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint24_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -975,7 +996,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint32_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint32_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint32_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint32_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint32_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint32_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -984,7 +1005,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint64_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint64_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint64_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint64_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint64_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint64_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -993,7 +1014,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int8_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int8_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int8_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int8_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int8_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int8_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -1002,7 +1023,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int16_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int16_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int16_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int16_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int16_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int16_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -1011,7 +1032,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int24_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int24_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int24_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int24_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int24_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int24_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -1020,7 +1041,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int32_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int32_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int32_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int32_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int32_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int32_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -1029,7 +1050,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int64_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int64_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int64_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int64_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int64_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int64_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -1038,7 +1059,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* 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_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_MASK Integer, String or UInt64 mask of this field, which must be 0 for framenum. */ /* WSLUA_OPTARG_ProtoField_framenum_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -1061,7 +1082,7 @@ static int ProtoField_boolean(lua_State* L, enum ftenum type) { const gchar* name = luaL_optstring(L,2,abbr); unsigned base = (unsigned)luaL_optinteger(L, 3, BASE_NONE); true_false_string* tfs = NULL; - guint32 mask = wslua_optguint32(L,5,0); + guint64 mask = get_mask(L,5,0); const gchar* blob = luaL_optstring(L,6,NULL); if (!name[0]) { @@ -1112,7 +1133,7 @@ static int ProtoField_boolean(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_bool_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_bool_DISPLAY How wide the parent bitfield is (`base.NONE` is used for NULL-value). */ /* WSLUA_OPTARG_ProtoField_bool_VALUESTRING A table containing the text that corresponds to the values. */ -/* WSLUA_OPTARG_ProtoField_bool_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_bool_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_bool_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -1434,7 +1455,7 @@ PROTOFIELD_OTHER(eui64,FT_EUI64) WSLUA_METAMETHOD ProtoField__tostring(lua_State* L) { /* Returns a string with info about a protofield (for debugging purposes). */ ProtoField f = checkProtoField(L,1); - gchar* s = ws_strdup_printf("ProtoField(%i): %s %s %s %s %p %.8x %s", + gchar* s = ws_strdup_printf("ProtoField(%i): %s %s %s %s %p %.16lx %s", f->hfid,f->name,f->abbrev, ftenum_to_string(f->type), base_to_string(f->base), |