Expose dissector_add_for_decode_as() to Lua

Allow Lua scripts to add their Protocol's dissector for "Decode as...".

Bug: 10696
Change-Id: Ic270cc85eff62ccfc29d8e5fcbb48247cfcd14bd
Reviewed-on: https://code.wireshark.org/review/6050
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Hadriel Kaplan 2014-12-25 10:17:11 -05:00 committed by Michael Mann
parent 5e16157de5
commit 016769d7e2
1 changed files with 24 additions and 0 deletions

View File

@ -2585,6 +2585,29 @@ WSLUA_METHOD DissectorTable_get_dissector (lua_State *L) {
}
}
WSLUA_METHOD DissectorTable_add_for_decode_as (lua_State *L) {
/*
Add the given `Proto` to the "Decode as..." list for this DissectorTable.
The passed-in `Proto` object's `dissector()` function is used for dissecting.
@since 1.99.1
*/
#define WSLUA_ARG_DissectorTable_add_for_decode_as_PROTO 2 /* The `Proto` to add. */
DissectorTable dt = checkDissectorTable(L,1);
Proto proto = checkProto(L, WSLUA_ARG_DissectorTable_add_for_decode_as_PROTO);
dissector_handle_t handle = NULL;
if (! proto->handle) {
proto->handle = new_register_dissector(proto->loname, dissect_lua, proto->hfid);
}
handle = proto->handle;
dissector_add_for_decode_as(dt->name, handle);
return 0;
}
/* XXX It would be nice to iterate and print which dissectors it has */
WSLUA_METAMETHOD DissectorTable__tostring(lua_State* L) {
/* Gets some debug information about the DissectorTable. */
@ -2638,6 +2661,7 @@ WSLUA_METHODS DissectorTable_methods[] = {
WSLUA_CLASS_FNREG(DissectorTable,remove_all),
WSLUA_CLASS_FNREG(DissectorTable,try),
WSLUA_CLASS_FNREG(DissectorTable,get_dissector),
WSLUA_CLASS_FNREG(DissectorTable,add_for_decode_as),
{ NULL, NULL }
};