forked from osmocom/wireshark
lua: Allow proto:register_heuristic to be used on multiple list names
In the C API, one can register a heuristic for the same protocol on different lists by specifying another unique short_name. This is impossible in the lua API, as the protocol name is used as the short name itself. This change fixes that by creating an unique shortname composed of the protocol name and the target list name. Change-Id: I2c30ce6e4f7a3b38879180c64cf8564f779163b4 Signed-off-by: Franklin "Snaipe" Mathieu <snaipe@diacritic.io> Reviewed-on: https://code.wireshark.org/review/18711 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
parent
67e1ed5252
commit
7f2a838922
|
@ -242,6 +242,7 @@ WSLUA_METHOD Proto_register_heuristic(lua_State* L) {
|
|||
const gchar *listname = luaL_checkstring(L, WSLUA_ARG_Proto_register_heuristic_LISTNAME);
|
||||
const gchar *proto_name = proto->name;
|
||||
const int top = lua_gettop(L);
|
||||
gchar *short_name;
|
||||
|
||||
if (!proto_name || proto->hfid == -1) {
|
||||
/* this shouldn't happen - internal bug if it does */
|
||||
|
@ -255,10 +256,15 @@ WSLUA_METHOD Proto_register_heuristic(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
short_name = wmem_strconcat(NULL, proto->loname, "_", listname, NULL);
|
||||
|
||||
/* verify that this is not already registered */
|
||||
if (find_heur_dissector_by_unique_short_name(proto->loname)) {
|
||||
if (find_heur_dissector_by_unique_short_name(short_name)) {
|
||||
wmem_free(NULL, short_name);
|
||||
luaL_error(L, "'%s' is already registered as heuristic", proto->loname);
|
||||
return 0;
|
||||
}
|
||||
wmem_free(NULL, short_name);
|
||||
|
||||
/* we'll check if the second form of this function was called: when the second arg is
|
||||
a Dissector obejct. The truth is we don't need the Dissector object to do this
|
||||
|
@ -318,10 +324,13 @@ WSLUA_METHOD Proto_register_heuristic(lua_State* L) {
|
|||
lua_pop(L,2); /* pop the lists table and the listname table */
|
||||
g_assert(top == lua_gettop(L));
|
||||
|
||||
short_name = wmem_strconcat(NULL, proto->loname, "_", listname, NULL);
|
||||
|
||||
/* now register the single/common heur_dissect_lua function */
|
||||
/* XXX - ADD PARAMETERS FOR NEW heur_dissector_add PARAMETERS!!! */
|
||||
heur_dissector_add(listname, heur_dissect_lua, proto_name, proto->loname, proto->hfid, HEURISTIC_ENABLE);
|
||||
heur_dissector_add(listname, heur_dissect_lua, proto_name, short_name, proto->hfid, HEURISTIC_ENABLE);
|
||||
|
||||
wmem_free(NULL, short_name);
|
||||
} else {
|
||||
luaL_argerror(L,3,"The heuristic dissector must be a function");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue