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
This commit is contained in:
Michael Mann 2013-10-22 17:41:06 +00:00
parent 1363444506
commit 17679ee25d
3 changed files with 33 additions and 1 deletions

View File

@ -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

View File

@ -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)

View File

@ -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);