diff options
author | Michael Mann <mmann78@netscape.net> | 2013-10-22 17:41:06 +0000 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2013-10-22 17:41:06 +0000 |
commit | 17679ee25d22b969a98a060c12edc99337f839ae (patch) | |
tree | 668bad597a8237f677577d21a39eb72fe5da89e8 | |
parent | 1363444506ed5a88a2c427dd31ec791ec572fe43 (diff) | |
download | wireshark-17679ee25d22b969a98a060c12edc99337f839ae.tar.gz |
Cannot define Field refering ProtoField defined in LUA. Bug 3513 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=3513)
When a new Field is created, does as following:
* Check whether that field is registered, by using `proto_registrar_get_byname`. This is current behavior.
* (patched) If not registered, check whether that field is defined in LUA and will be registered. This is performed in `wslua_is_field_available` accessing LUA context.
* If not, an error "a field with this name must exist" occurs.
svn path=/trunk/; revision=52771
-rw-r--r-- | epan/wslua/wslua.h | 2 | ||||
-rw-r--r-- | epan/wslua/wslua_field.c | 2 | ||||
-rw-r--r-- | epan/wslua/wslua_proto.c | 30 |
3 files changed, 33 insertions, 1 deletions
diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index 73f97e0d4b..6a298233b0 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -463,4 +463,6 @@ extern int wslua_set_tap_enums(lua_State* L); extern int luaopen_bit(lua_State *L); +extern int wslua_is_field_available(lua_State* L, const char* field_abbr); + #endif diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c index 6ecd2f44aa..cd3aa6e3c8 100644 --- a/epan/wslua/wslua_field.c +++ b/epan/wslua/wslua_field.c @@ -483,7 +483,7 @@ WSLUA_CONSTRUCTOR Field_new(lua_State *L) { if (!name) return 0; - if (!proto_registrar_get_byname(name)) + if (!proto_registrar_get_byname(name) && !wslua_is_field_available(L, name)) WSLUA_ARG_ERROR(Field_new,FIELDNAME,"a field with this name must exist"); if (!wanted_fields) diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index 3700ed00a6..146a99e8a5 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -1595,6 +1595,36 @@ int Proto_register(lua_State* L) { return 1; } +/** + * Query field abbr that is defined and bound to a Proto in lua. + * They are not registered untill the end of the initialization. + */ +int wslua_is_field_available(lua_State* L, const char* field_abbr) { + lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref); + lua_pushnil(L); + while (lua_next(L, -2)) { + Proto proto; + proto = checkProto(L, -1); + + lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields); + + lua_pushnil(L); + while (lua_next(L, -2)) { + ProtoField f = checkProtoField(L, -1); + if (strcmp(field_abbr, f->abbr) == 0) { + /* found! */ + lua_pop(L, 6); + return 1; + } + lua_pop(L, 1); /* table value */ + } + lua_pop(L, 2); /* proto->fields and table value */ + } + lua_pop(L, 1); /* protocols_table_ref */ + + return 0; +} + int Proto_commit(lua_State* L) { lua_settop(L,0); lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref); |