aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFranklin "Snaipe" Mathieu <snaipe@diacritic.io>2016-11-08 17:13:41 +0100
committerAlexis La Goutte <alexis.lagoutte@gmail.com>2016-11-13 17:48:30 +0000
commit7f2a83892204821145768b76bbdd0719b57787f8 (patch)
treeb9131611660984d1229b055fc9929a535c779e9b
parent67e1ed5252ae27e3becdb6108683ba053de87cce (diff)
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>
-rw-r--r--epan/wslua/wslua_proto.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c
index 6bdecd4392..acbdb67e76 100644
--- a/epan/wslua/wslua_proto.c
+++ b/epan/wslua/wslua_proto.c
@@ -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");
}