Fix Bug 9728 'Lua: ProtoField.bool() VALUESTRING argument is not optional but was supposed to be'

Similar to bug 9725 and ProtoField.new(), the way the VALUESTRING argument is being checked
in the code for ProtoField.bool() ends up making it non-optional.  This patch fixes that,
along with some minor API documentation fixes (text).

Change-Id: Iadb9a8ace9c5514fc623d882301fe16b637fe4ce
Reviewed-on: https://code.wireshark.org/review/125
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Evan Huus <eapache@gmail.com>
This commit is contained in:
Hadriel Kaplan 2014-02-06 01:33:12 -05:00 committed by Evan Huus
parent 373bf9bd86
commit 217f9fd0d9
3 changed files with 33 additions and 15 deletions

View File

@ -666,7 +666,7 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) {
WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be used in a protocol. */
#define WSLUA_ARG_ProtoField_new_NAME 1 /* Actual name of the field (the string that 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.NONE, ftypes.BOOLEAN,
#define WSLUA_ARG_ProtoField_new_TYPE 3 /* Field Type: one of ftypes.BOOLEAN,
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, ftypes.STRINGZ, ftypes.UINT_STRING, ftypes.ETHER, ftypes.BYTES
@ -1013,7 +1013,7 @@ static int ProtoField_boolean(lua_State* L, enum ftenum type) {
const gchar* abbr = luaL_checkstring(L,1);
const gchar* name = luaL_optstring(L,2,abbr);
unsigned base = luaL_optint(L, 3, BASE_NONE);
true_false_string* tfs = (lua_gettop(L) > 3) ? true_false_string_from_table(L,4) : NULL;
true_false_string* tfs = NULL;
guint32 mask = (guint32)luaL_optnumber(L,5,0);
const gchar* blob = luaL_optstring(L,6,NULL);
@ -1039,6 +1039,10 @@ static int ProtoField_boolean(lua_State* L, enum ftenum type) {
return 0;
}
if (lua_gettop(L) > 3 && !lua_isnil(L,4)) {
tfs = true_false_string_from_table(L,4);
}
f = g_new(wslua_field_t,1);
f->hfid = -2;

View File

@ -250,6 +250,8 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) {
const gchar* s = lua_tostring(L,1);
item = proto_tree_add_text(tree_item->tree, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len,"%s",s);
lua_remove(L,1);
} else {
luaL_error(L,"Tree item ProtoField/Protocol handle is invalid (ProtoField/Proto not registered?)");
}
}
@ -272,20 +274,32 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) {
WSLUA_METHOD TreeItem_add(lua_State *L) {
/*
Adds an child item to a given item, returning the child.
tree_item:add([proto_field | proto], [tvbrange], [label], ...)
if the proto_field represents a numeric value (int, uint or float) is to be treated as a Big Endian (network order) Value.
Adds a child item to this tree item, returning the new child TreeItem.
if the protofield represents a numeric value (int, uint or float), then it's treated as a Big Endian (network order) value.
This function has a complicated form: 'treeitem:add(protofield, [tvbrange,] [[value], label]])', such that if the second
argument is a tvbrange, and a third argument is given, it's a value; but if the second argument is a non-tvbrange type, then
it is the value (as opposed to filling that argument with 'nil', which is invalid for this function).
*/
WSLUA_RETURN(TreeItem_add_item_any(L,FALSE)); /* The child item */
#define WSLUA_ARG_TreeItem_add_PROTOFIELD 2 /* The ProtoField field or Proto protocol object to add to the tree. */
#define WSLUA_OPTARG_TreeItem_add_TVBRANGE 3 /* The TvbRange of bytes in the packet this tree item covers/represents. */
#define WSLUA_OPTARG_TreeItem_add_VALUE 4 /* The field's value, instead of the ProtoField/Proto one. */
#define WSLUA_OPTARG_TreeItem_add_LABEL 5 /* One or more strings to use for the tree item label, instead of the ProtoField/Proto one. */
WSLUA_RETURN(TreeItem_add_item_any(L,FALSE)); /* The new child TreeItem */
}
WSLUA_METHOD TreeItem_add_le(lua_State *L) {
/*
Adds (and returns) an child item to a given item, returning the child.
tree_item:add([proto_field | proto], [tvbrange], [label], ...)
if the proto_field represents a numeric value (int, uint or float) is to be treated as a Little Endian Value.
Adds a child item to this tree item, returning the new child TreeItem.
if the protofield represents a numeric value (int, uint or float), then it's treated as a Little Endian value.
This function has a complicated form: 'treeitem:add_le(protofield, [tvbrange,] [[value], label]])', such that if the second
argument is a tvbrange, and a third argument is given, it's a value; but if the second argument is a non-tvbrange type, then
it is the value (as opposed to filling that argument with 'nil', which is invalid for this function).
*/
WSLUA_RETURN(TreeItem_add_item_any(L,TRUE)); /* The child item */
#define WSLUA_ARG_TreeItem_add_le_PROTOFIELD 2 /* The ProtoField field or Proto protocol object to add to the tree. */
#define WSLUA_OPTARG_TreeItem_add_le_TVBRANGE 3 /* The TvbRange of bytes in the packet this tree item covers/represents. */
#define WSLUA_OPTARG_TreeItem_add_le_VALUE 4 /* The field's value, instead of the ProtoField/Proto one. */
#define WSLUA_OPTARG_TreeItem_add_le_LABEL 5 /* One or more strings to use for the tree item label, instead of the ProtoField/Proto one. */
WSLUA_RETURN(TreeItem_add_item_any(L,TRUE)); /* The new child TreeItem */
}
WSLUA_METHOD TreeItem_set_text(lua_State *L) {

View File

@ -250,7 +250,7 @@ WSLUA_METHOD ByteArray_subset(lua_State* L) {
WSLUA_RETURN(1); /* A ByteArray contaning the requested segment. */
}
static int ByteArray_base64_decode(lua_State* L) {
WSLUA_METHOD ByteArray_base64_decode(lua_State* L) {
/* Obtain a base64 decoded ByteArray */
ByteArray ba = checkByteArray(L,1);
ByteArray ba2;
@ -272,8 +272,8 @@ static int ByteArray_base64_decode(lua_State* L) {
WSLUA_RETURN(1); /* The created ByteArray. */
}
static int ByteArray_tostring(lua_State* L) {
/* Obtain a string containing the bytes in a ByteArray so that it can be used in display filters (e.g. "01:23:45:67:89:AB") */
WSLUA_METAMETHOD ByteArray__tostring(lua_State* L) {
/* Obtain a string containing the bytes in a ByteArray so that it can be used in display filters (e.g. "01FE456789AB") */
static const char byte_to_str[][3] = {
"00","01","02","03","04","05","06","07","08","09","0A","0B","0C","0D","0E","0F",
"10","11","12","13","14","15","16","17","18","19","1A","1B","1C","1D","1E","1F",
@ -307,7 +307,7 @@ static int ByteArray_tostring(lua_State* L) {
lua_pushstring(L,s->str);
g_string_free(s,TRUE);
WSLUA_RETURN(1); /* A string contaning a representaion of the ByteArray. */
WSLUA_RETURN(1); /* A hex-ascii string containing a representation of the ByteArray. */
}
static int ByteArray_tvb (lua_State *L);
@ -327,7 +327,7 @@ static const luaL_Reg ByteArray_methods[] = {
};
static const luaL_Reg ByteArray_meta[] = {
{"__tostring", ByteArray_tostring},
{"__tostring", ByteArray__tostring},
{"__concat", ByteArray__concat},
{"__call",ByteArray_subset},
{ NULL, NULL }