diff --git a/epan/proto.h b/epan/proto.h index 7a955be27f..86000a8097 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -522,11 +522,12 @@ typedef enum { BASE_FLOAT = BASE_NONE, /**< decimal-format float */ /* String types */ - STR_ASCII = BASE_NONE, /**< shows non-printable ASCII characters as C-style escapes */ + STR_ASCII = 0, /**< shows non-printable ASCII characters as C-style escapes */ /* XXX, support for format_text_wsp() ? */ STR_UNICODE = 7, /**< shows non-printable UNICODE characters as \\uXXXX (XXX for now non-printable characters display depends on UI) */ -/* Byte types */ +/* Byte separators */ + SEP_NONE = 0, /**< hexadecimal bytes with no separator */ SEP_DOT = 8, /**< hexadecimal bytes with a period (.) between each byte */ SEP_DASH = 9, /**< hexadecimal bytes with a dash (-) between each byte */ SEP_COLON = 10, /**< hexadecimal bytes with a colon (:) between each byte */ diff --git a/epan/wslua/make-init-lua.pl b/epan/wslua/make-init-lua.pl index 9c848048c1..b7abfd7f11 100755 --- a/epan/wslua/make-init-lua.pl +++ b/epan/wslua/make-init-lua.pl @@ -39,6 +39,8 @@ my $frametypes_table = ''; my $wtap_rec_types_table = ''; my $wtap_presence_flags_table = ''; my $bases_table = ''; +my $str_type_table = ''; +my $byte_sep_table = ''; my $encodings = ''; my $expert_pi = ''; my $expert_pi_tbl = ''; @@ -56,6 +58,8 @@ my %replacements = %{{ WTAP_REC_TYPES => \$wtap_rec_types_table, WTAP_PRESENCE_FLAGS => \$wtap_presence_flags_table, BASES => \$bases_table, + STRING_TYPES => \$str_type_table, + BYTE_SEPARATORS => \$byte_sep_table, ENCODINGS => \$encodings, EXPERT => \$expert_pi, EXPERT_TABLE => \$expert_pi_tbl, @@ -165,6 +169,8 @@ $frametypes_table =~ s/,\n$/\n}\n/msi; # $bases_table = "-- Display Bases\n base = {\n"; +$str_type_table = "-- String Types\n str = {\n"; +$byte_sep_table = "-- Byte Separators\n sep = {\n"; $encodings = "-- Encodings\n"; $expert_pi = "-- Expert flags and facilities (deprecated - see 'expert' table below)\n"; $expert_pi_tbl = "-- Expert flags and facilities\nexpert = {\n"; @@ -190,6 +196,14 @@ while() { $bases_table .= "\t[\"$1\"] = $num,\n"; } + if (/^\s+STR_([A-Z_]+)[ ]*=[ ]*([0-9]+),/ ) { + $str_type_table .= "\t[\"$1\"] = $2,\n"; + } + + if (/^\s+SEP_([A-Z_]+)[ ]*=[ ]*([0-9]+),/ ) { + $byte_sep_table .= "\t[\"$1\"] = $2,\n"; + } + if (/^.define\s+PI_SEVERITY_MASK /) { $in_severity = 1; $skip_this = 1; @@ -251,6 +265,8 @@ close STAT_GROUPS; $bases_table .= "}\n\n"; +$str_type_table .= "}\n\n"; +$byte_sep_table .= "}\n\n"; $encodings .= "\n\n"; $expert_pi .= "\n"; $expert_pi_severity .= "\t},\n"; diff --git a/epan/wslua/template-init.lua b/epan/wslua/template-init.lua index 4850ccb4d1..5891f055ff 100644 --- a/epan/wslua/template-init.lua +++ b/epan/wslua/template-init.lua @@ -130,6 +130,12 @@ end -- %BASES% +-- the following table is since 2.4 +-- %STRING_TYPES% + +-- the following table is since 2.4 +-- %BYTE_SEPARATORS% + -- %ENCODINGS% -- %EXPERT% diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c index df2de1046a..6eb3bb85da 100644 --- a/epan/wslua/wslua_proto_field.c +++ b/epan/wslua/wslua_proto_field.c @@ -106,6 +106,15 @@ static const struct field_display_string_t base_displays[] = { {"base.DEC_HEX", BASE_DEC_HEX}, {"base.HEX_DEC", BASE_HEX_DEC}, {"base.UNIT_STRING", BASE_UNIT_STRING}, + /* String types */ + {"str.ASCII", STR_ASCII}, + {"str.UNICODE", STR_UNICODE}, + /* Byte separators */ + {"sep.NONE", SEP_NONE}, + {"sep.DOT", SEP_DOT}, + {"sep.DASH", SEP_DASH}, + {"sep.COLON", SEP_COLON}, + {"sep.SPACE", SEP_SPACE}, /* for FT_BOOLEAN, how wide the parent bitfield is */ {"8",8}, {"16",16}, @@ -534,6 +543,28 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { return 0; } break; + case FT_STRING: + case FT_STRINGZ: + if (base != STR_ASCII && base != STR_UNICODE) { + WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Display must be either str.ASCII or str.UNICODE"); + return 0; + } + if (mask) { + WSLUA_OPTARG_ERROR(ProtoField_new,MASK,"This type can not have a bitmask"); + return 0; + } + break; + case FT_BYTES: + case FT_UINT_BYTES: + if (base != SEP_NONE && (base < SEP_DOT || base > SEP_SPACE)) { + WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Display must be either sep.NONE, sep.DOT, sep.DASH, sep.COLON or sep.SPACE"); + return 0; + } + if (mask) { + WSLUA_OPTARG_ERROR(ProtoField_new,MASK,"This type can not have a bitmask"); + return 0; + } + break; case FT_FLOAT: case FT_DOUBLE: if ((base & BASE_UNIT_STRING) && @@ -550,10 +581,6 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { case FT_IPXNET: case FT_ETHER: case FT_RELATIVE_TIME: - case FT_STRING: - case FT_STRINGZ: - case FT_BYTES: - case FT_UINT_BYTES: case FT_GUID: case FT_OID: case FT_PROTOCOL: @@ -1010,6 +1037,93 @@ static int ProtoField_floating(lua_State* L,enum ftenum type) { PROTOFIELD_FLOATING(float,FT_FLOAT) PROTOFIELD_FLOATING(double,FT_DOUBLE) +static int ProtoField_other_display(lua_State* L,enum ftenum type) { + ProtoField f; + const gchar* abbr = check_field_name(L,1,type); + const gchar* name = luaL_optstring(L,2,abbr); + unsigned base = BASE_NONE; + const gchar* blob; + + if (!name[0]) { + luaL_argerror(L, 2, "cannot be an empty string"); + return 0; + } + + if (lua_isnumber(L, 3)) { + base = (unsigned)luaL_optinteger(L,3,BASE_NONE); + if (type == FT_STRING || type == FT_STRINGZ) { + if (base != STR_ASCII && base != STR_UNICODE) { + luaL_argerror(L, 3, "Display must be either str.ASCII or str.UNICODE"); + return 0; + } + } else if (type == FT_BYTES || type == FT_UINT_BYTES) { + if (base != SEP_NONE && (base < SEP_DOT || base > SEP_SPACE)) { + luaL_argerror(L, 3, "Display must be either sep.NONE, sep.DOT, sep.DASH, sep.COLON or sep.SPACE"); + return 0; + } + } + + blob = luaL_optstring(L,4,NULL); + } else { + blob = luaL_optstring(L,3,NULL); + } + + f = g_new(wslua_field_t,1); + + f->hfid = -2; + f->ett = -1; + f->name = g_strdup(name); + f->abbrev = g_strdup(abbr); + f->type = type; + f->vs = NULL; + f->base = base; + f->mask = 0; + if (blob && strcmp(blob, f->name) != 0) { + f->blob = g_strdup(blob); + } else { + f->blob = NULL; + } + + pushProtoField(L,f); + + return 1; +} + +#define PROTOFIELD_OTHER_DISPLAY(lower,FT) static int ProtoField_##lower(lua_State* L) { return ProtoField_other_display(L,FT); } +/* _WSLUA_CONSTRUCTOR_ ProtoField_string Creates a `ProtoField` of a string value. */ +/* WSLUA_ARG_Protofield_string_ABBR Abbreviated name of the field (the string used in filters). */ +/* WSLUA_OPTARG_Protofield_string_NAME Actual name of the field (the string that appears in the tree). */ +/* WSLUA_OPTARG_Protofield_string_DISPLAY One of `str.ASCII` or `str.UNICODE`. */ +/* WSLUA_OPTARG_Protofield_string_DESC Description of the field. */ +/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ + +/* _WSLUA_CONSTRUCTOR_ ProtoField_stringz Creates a `ProtoField` of a zero-terminated string value. */ +/* WSLUA_ARG_Protofield_stringz_ABBR Abbreviated name of the field (the string used in filters). */ +/* WSLUA_OPTARG_Protofield_stringz_NAME Actual name of the field (the string that appears in the tree). */ +/* WSLUA_OPTARG_Protofield_stringz_DISPLAY One of `str.ASCII` or `str.UNICODE`. */ +/* WSLUA_OPTARG_Protofield_stringz_DESC Description of the field. */ +/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ + +/* _WSLUA_CONSTRUCTOR_ ProtoField_bytes Creates a `ProtoField` for an arbitrary number of bytes. */ +/* WSLUA_ARG_Protofield_bytes_ABBR Abbreviated name of the field (the string used in filters). */ +/* WSLUA_OPTARG_Protofield_bytes_NAME Actual name of the field (the string that appears in the tree). */ +/* WSLUA_OPTARG_Protofield_bytes_DISPLAY One of `sep.NONE`, `sep.DOT`, `sep.DASH`, `sep.COLON` or `sep.SPACE`. */ +/* WSLUA_OPTARG_Protofield_bytes_DESC Description of the field. */ +/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ + +/* _WSLUA_CONSTRUCTOR_ ProtoField_ubytes Creates a `ProtoField` for an arbitrary number of unsigned bytes. */ +/* WSLUA_ARG_Protofield_ubytes_ABBR Abbreviated name of the field (the string used in filters). */ +/* WSLUA_OPTARG_Protofield_ubytes_NAME Actual name of the field (the string that appears in the tree). */ +/* WSLUA_OPTARG_Protofield_ubytes_DISPLAY One of `sep.NONE`, `sep.DOT`, `sep.DASH`, `sep.COLON` or `sep.SPACE`. */ +/* WSLUA_OPTARG_Protofield_ubytes_DESC Description of the field. */ +/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ + + +PROTOFIELD_OTHER_DISPLAY(string,FT_STRING) +PROTOFIELD_OTHER_DISPLAY(stringz,FT_STRINGZ) +PROTOFIELD_OTHER_DISPLAY(bytes,FT_BYTES) +PROTOFIELD_OTHER_DISPLAY(ubytes,FT_UINT_BYTES) + static int ProtoField_other(lua_State* L,enum ftenum type) { ProtoField f; const gchar* abbr = check_field_name(L,1,type); @@ -1067,30 +1181,6 @@ static int ProtoField_other(lua_State* L,enum ftenum type) { /* WSLUA_OPTARG_Protofield_ether_DESC Description of the field. */ /* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ -/* _WSLUA_CONSTRUCTOR_ ProtoField_string Creates a `ProtoField` of a string value. */ -/* WSLUA_ARG_Protofield_string_ABBR Abbreviated name of the field (the string used in filters). */ -/* WSLUA_OPTARG_Protofield_string_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_Protofield_string_DESC Description of the field. */ -/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ - -/* _WSLUA_CONSTRUCTOR_ ProtoField_stringz Creates a `ProtoField` of a zero-terminated string value. */ -/* WSLUA_ARG_Protofield_stringz_ABBR Abbreviated name of the field (the string used in filters). */ -/* WSLUA_OPTARG_Protofield_stringz_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_Protofield_stringz_DESC Description of the field. */ -/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ - -/* _WSLUA_CONSTRUCTOR_ ProtoField_bytes Creates a `ProtoField` for an arbitrary number of bytes. */ -/* WSLUA_ARG_Protofield_bytes_ABBR Abbreviated name of the field (the string used in filters). */ -/* WSLUA_OPTARG_Protofield_bytes_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_Protofield_bytes_DESC Description of the field. */ -/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ - -/* _WSLUA_CONSTRUCTOR_ ProtoField_ubytes Creates a `ProtoField` for an arbitrary number of unsigned bytes. */ -/* WSLUA_ARG_Protofield_ubytes_ABBR Abbreviated name of the field (the string used in filters). */ -/* WSLUA_OPTARG_Protofield_ubytes_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_Protofield_ubytes_DESC Description of the field. */ -/* _WSLUA_RETURNS_ A `ProtoField` object to be added to a table set to the `Proto.fields` attribute. */ - /* _WSLUA_CONSTRUCTOR_ ProtoField_guid Creates a `ProtoField` for a Globally Unique IDentifier (GUID). */ /* WSLUA_ARG_Protofield_guid_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_Protofield_guid_NAME Actual name of the field (the string that appears in the tree). */ @@ -1133,10 +1223,6 @@ PROTOFIELD_OTHER(ipv6,FT_IPv6) PROTOFIELD_OTHER(ipx,FT_IPXNET) PROTOFIELD_OTHER(ether,FT_ETHER) PROTOFIELD_OTHER(relative_time,FT_RELATIVE_TIME) -PROTOFIELD_OTHER(string,FT_STRING) -PROTOFIELD_OTHER(stringz,FT_STRINGZ) -PROTOFIELD_OTHER(bytes,FT_BYTES) -PROTOFIELD_OTHER(ubytes,FT_UINT_BYTES) PROTOFIELD_OTHER(guid,FT_GUID) PROTOFIELD_OTHER(oid,FT_OID) PROTOFIELD_OTHER(protocol,FT_PROTOCOL)