aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--epan/wslua/wslua_proto_field.c34
-rw-r--r--test/lua/protofield.lua21
2 files changed, 44 insertions, 11 deletions
diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c
index 7a463cadc0..c050cdefbc 100644
--- a/epan/wslua/wslua_proto_field.c
+++ b/epan/wslua/wslua_proto_field.c
@@ -28,6 +28,7 @@ WSLUA_CLASS_DEFINE(ProtoField,FAIL_ON_NULL("null ProtoField"));
static const wslua_ft_types_t ftenums[] = {
{"ftypes.NONE", FT_NONE},
{"ftypes.BOOLEAN", FT_BOOLEAN},
+ {"ftypes.CHAR", FT_CHAR},
{"ftypes.UINT8", FT_UINT8},
{"ftypes.UINT16", FT_UINT16},
{"ftypes.UINT24", FT_UINT24},
@@ -510,7 +511,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
appears in the tree). */
#define WSLUA_ARG_ProtoField_new_ABBR 2 /* Filter name of the field (the string that
is used in filters). */
-#define WSLUA_ARG_ProtoField_new_TYPE 3 /* Field Type: one of: `ftypes.BOOLEAN`, `ftypes.UINT8`,
+#define WSLUA_ARG_ProtoField_new_TYPE 3 /* Field Type: one of: `ftypes.BOOLEAN`, `ftypes.CHAR`, `ftypes.UINT8`,
`ftypes.UINT16`, `ftypes.UINT24`, `ftypes.UINT32`, `ftypes.UINT64`, `ftypes.INT8`,
`ftypes.INT16`, `ftypes.INT24`, `ftypes.INT32`, `ftypes.INT64`, `ftypes.FLOAT`,
`ftypes.DOUBLE` , `ftypes.ABSOLUTE_TIME`, `ftypes.RELATIVE_TIME`, `ftypes.STRING`,
@@ -586,6 +587,14 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
}
break;
case FT_CHAR:
+ if (nargs < WSLUA_OPTARG_ProtoField_new_BASE || lua_isnil(L, WSLUA_OPTARG_ProtoField_new_BASE)) {
+ base = BASE_OCT; /* Default base for characters (BASE_HEX instead?) */
+ }
+ if (base & BASE_UNIT_STRING) {
+ WSLUA_OPTARG_ERROR(ProtoField_new, BASE, "Character type can not use base.UNIT_STRING");
+ return 0;
+ }
+ /* FALLTHRU */
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
@@ -596,11 +605,11 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
case FT_INT24:
case FT_INT32:
case FT_INT64:
- if (type != FT_CHAR && base & BASE_UNIT_STRING) {
+ if (base & BASE_UNIT_STRING) {
base_unit_string = TRUE;
base &= ~BASE_UNIT_STRING;
}
- if (type != FT_CHAR && base & BASE_RANGE_STRING) {
+ if (base & BASE_RANGE_STRING) {
base_range_string = TRUE;
base &= ~BASE_RANGE_STRING;
}
@@ -608,14 +617,15 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
WSLUA_OPTARG_ERROR(ProtoField_new, BASE, "Only one of base.UNIT_STRING and base.RANGE_STRING can be specified");
return 0;
}
-
- if (base == BASE_NONE) {
- if (type == FT_CHAR)
- base = BASE_OCT; /* default base for characters (BASE_HEX instead?) */
- else
- base = BASE_DEC; /* Default base for integer */
+ if (type != FT_CHAR && base == BASE_NONE) {
+ base = BASE_DEC; /* Default base for integer */
}
- if ((base != BASE_DEC) &&
+ if (type == FT_CHAR) {
+ if (base != BASE_NONE && base != BASE_HEX && base != BASE_OCT) {
+ luaL_argerror(L, 3, "Base must be either base.NONE, base.HEX or base.OCT");
+ return 0;
+ }
+ } else if ((base != BASE_DEC) &&
(type == FT_INT8 || type == FT_INT16 || type == FT_INT24 || type == FT_INT32 || type == FT_INT64))
{
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either base.DEC or base.UNIT_STRING");
@@ -636,6 +646,10 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) {
vs32 = value_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING);
}
}
+ if (type == FT_CHAR && base == BASE_NONE && rs32 == NULL && vs32 == NULL) {
+ luaL_argerror(L, 3, "Base base.NONE must be used with a valuestring");
+ return 0;
+ }
break;
case FT_BOOLEAN:
if (mask == 0x0 && base != BASE_NONE) {
diff --git a/test/lua/protofield.lua b/test/lua/protofield.lua
index 6b6110ddff..2fcfafb2fd 100644
--- a/test/lua/protofield.lua
+++ b/test/lua/protofield.lua
@@ -30,7 +30,7 @@ local function setFailed(name)
end
-- expected number of runs
-local taptests = { [OTHER]=32 }
+local taptests = { [OTHER]=38 }
local function getResults()
print("\n-----------------------------\n")
for k,v in pairs(taptests) do
@@ -72,6 +72,25 @@ test_proto.fields.time_field = ProtoField.uint16("test.time", "Time", base.UNIT_
test_proto.fields.dist_field = ProtoField.uint16("test.dist", "Distance", base.UNIT_STRING, {" km"})
test_proto.fields.filtered_field = ProtoField.uint16("test.filtered", "Filtered Field", base.DEC)
+-- Field type: CHAR
+success = pcall(ProtoField.new, "char", "test.char0", ftypes.CHAR)
+test("ProtoField-char", success)
+
+success = pcall(ProtoField.new, "char base NONE without valuestring", "test.char1", ftypes.CHAR, nil, base.NONE)
+test("ProtoField-char-without-valuestring", not success)
+
+success = pcall(ProtoField.new, "char base NONE with valuestring", "test.char2", ftypes.CHAR, {1, "Value"}, base.NONE)
+test("ProtoField-char-with-valuestring", success)
+
+success = pcall(ProtoField.new, "char base DEC", "test.char3", ftypes.CHAR, nil, base.DEC)
+test("ProtoField-char-base-dec", not success)
+
+success = pcall(ProtoField.new, "char base UNIT_STRING", "test.char4", ftypes.CHAR, {" m"}, base.UNIT_STRING)
+test("ProtoField-char-unit-string", not success)
+
+success = pcall(ProtoField.new, "char base RANGE_STRING", "test.char5", ftypes.CHAR, {{1, 2, "Value"}}, base.RANGE_STRING)
+test("ProtoField-char-range-string", success)
+
-- Field name: empty, illegal, incompatible
success = pcall(ProtoField.int8, nil, "empty field name 1")
test("ProtoField-empty-field-name-1", not success)