From 0837dd23ec0df1446c2912f378eb9fefe3fe362d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Wed, 15 Mar 2017 09:21:18 +0100 Subject: [PATCH] Lua: Add absolute time base values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add ABSOLUTE_TIME_* defines to the base table in init.lua for use in ProtoField.absolute_time. Change-Id: I5c99eafdac97655d71fd4f3374294cd587afaf0a Reviewed-on: https://code.wireshark.org/review/20543 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- epan/wslua/make-init-lua.pl | 20 ++++++++++++++++++++ epan/wslua/wslua_proto_field.c | 18 +++++++++++++----- test/lua/tvb.lua | 4 ++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/epan/wslua/make-init-lua.pl b/epan/wslua/make-init-lua.pl index 45035e1f5c..eea8f331eb 100755 --- a/epan/wslua/make-init-lua.pl +++ b/epan/wslua/make-init-lua.pl @@ -226,6 +226,26 @@ while() { } close PROTO_H; +# +# Extract values from time_fmt.h: +# +# ABSOLUTE_TIME_XXX values for absolute time bases +# + +my $absolute_time_num = 0; + +open TIME_FMT_H, "< $WSROOT/epan/time_fmt.h" or die "cannot open '$WSROOT/epan/time_fmt.h': $!"; +while() { + if (/^\s+ABSOLUTE_TIME_([A-Z_]+)[ ]*=[ ]*([0-9]+)[,\s]+(?:\/\* (.*?) \*\/)?/) { + $bases_table .= "\t[\"$1\"] = $2, -- $3\n"; + $absolute_time_num = $2 + 1; + } elsif (/^\s+ABSOLUTE_TIME_([A-Z_]+)[,\s]+(?:\/\* (.*?) \*\/)?/) { + $bases_table .= "\t[\"$1\"] = $absolute_time_num, -- $2\n"; + $absolute_time_num++; + } +} +close TIME_FTM_H; + # # Extract values from stat_groups.h: # diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c index 44e0d354cc..f9738f35c8 100644 --- a/epan/wslua/wslua_proto_field.c +++ b/epan/wslua/wslua_proto_field.c @@ -98,6 +98,11 @@ struct field_display_string_t { unsigned base; }; +/* + * This table is primarily used to convert from string representation + * to int representation in string_to_base(). + * Some string values are added for backward compatibility. + */ static const struct field_display_string_t base_displays[] = { {"base.NONE", BASE_NONE}, {"base.DEC", BASE_DEC}, @@ -120,9 +125,12 @@ static const struct field_display_string_t base_displays[] = { {"24",24}, {"32",32}, /* for FT_ABSOLUTE_TIME use values in absolute_time_display_e */ - {"LOCAL", ABSOLUTE_TIME_LOCAL}, - {"UTC", ABSOLUTE_TIME_UTC}, - {"DOY_UTC", ABSOLUTE_TIME_DOY_UTC}, + {"base.LOCAL", ABSOLUTE_TIME_LOCAL}, + {"base.UTC", ABSOLUTE_TIME_UTC}, + {"base.DOY_UTC", ABSOLUTE_TIME_DOY_UTC}, + {"LOCAL", ABSOLUTE_TIME_LOCAL}, /* for backward compatibility */ + {"UTC", ABSOLUTE_TIME_UTC}, /* for backward compatibility */ + {"DOY_UTC", ABSOLUTE_TIME_DOY_UTC}, /* for backward compatibility */ {NULL,0} }; @@ -534,7 +542,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { if (base == BASE_NONE) { base = ABSOLUTE_TIME_LOCAL; /* Default base for FT_ABSOLUTE_TIME */ } else if (base < ABSOLUTE_TIME_LOCAL || base > ABSOLUTE_TIME_DOY_UTC) { - WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either LOCAL, UTC, or DOY_UTC"); + WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either base.LOCAL, base.UTC, or base.DOY_UTC"); return 0; } if (mask) { @@ -945,7 +953,7 @@ static int ProtoField_time(lua_State* L,enum ftenum type) { if (type == FT_ABSOLUTE_TIME) { if (base < ABSOLUTE_TIME_LOCAL || base > ABSOLUTE_TIME_DOY_UTC) { - luaL_argerror(L, 3, "Base must be either LOCAL, UTC, or DOY_UTC"); + luaL_argerror(L, 3, "Base must be either base.LOCAL, base.UTC, or base.DOY_UTC"); return 0; } } diff --git a/test/lua/tvb.lua b/test/lua/tvb.lua index 1eb576c973..e03a7b61b4 100644 --- a/test/lua/tvb.lua +++ b/test/lua/tvb.lua @@ -155,7 +155,7 @@ local testfield = OID = ProtoField.oid ("test.basic.oid", "Basic OID"), REL_OID = ProtoField.rel_oid("test.basic.rel_oid", "Basic Relative OID"), ABSOLUTE_LOCAL = ProtoField.absolute_time("test.basic.absolute.local","Basic absolute local"), - ABSOLUTE_UTC = ProtoField.absolute_time("test.basic.absolute.utc", "Basic absolute utc", 1001), + ABSOLUTE_UTC = ProtoField.absolute_time("test.basic.absolute.utc", "Basic absolute utc", base.UTC), IPv4 = ProtoField.ipv4 ("test.basic.ipv4", "Basic ipv4 address"), IPv6 = ProtoField.ipv6 ("test.basic.ipv6", "Basic ipv6 address"), -- GUID = ProtoField.guid ("test.basic.guid", "Basic GUID"), @@ -164,7 +164,7 @@ local testfield = time = { ABSOLUTE_LOCAL = ProtoField.absolute_time("test.time.absolute.local","Time absolute local"), - ABSOLUTE_UTC = ProtoField.absolute_time("test.time.absolute.utc", "Time absolute utc", 1001), + ABSOLUTE_UTC = ProtoField.absolute_time("test.time.absolute.utc", "Time absolute utc", base.UTC), }, bytes =