From bb09bed96920d62d184b3e48135f0ca63e844f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Fri, 8 Dec 2023 15:06:54 +0000 Subject: wslua: Add support for SPDX/URL/Description info --- epan/wslua/init_wslua.c | 19 ++++++++++++----- epan/wslua/wslua.h | 5 ++++- epan/wslua/wslua_utility.c | 53 ++++++++++++++++++++++++++++++++-------------- ui/qt/about_dialog.cpp | 6 +++--- 4 files changed, 58 insertions(+), 25 deletions(-) diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c index 779a5f42e6..faa5c8f91e 100644 --- a/epan/wslua/init_wslua.c +++ b/epan/wslua/init_wslua.c @@ -34,6 +34,9 @@ typedef struct _wslua_plugin { gchar *name; /**< plugin name */ gchar *version; /**< plugin version */ + gchar *spdx_id; /**< plugin SPDX ID */ + gchar *home_url; /**< plugin homepage */ + gchar *blurb; /**< plugin description */ gchar *filename; /**< plugin filename */ plugin_scope_e scope; /**< plugin scope */ struct _wslua_plugin *next; @@ -550,7 +553,7 @@ static int error_handler_with_callback(lua_State *LS) { return 1; } -static void wslua_add_plugin(const gchar *name, const gchar *version, +static void wslua_add_plugin(const gchar *name, const gchar *filename, plugin_scope_e scope) { wslua_plugin *new_plug, *lua_plug; @@ -568,10 +571,16 @@ static void wslua_add_plugin(const gchar *name, const gchar *version, } new_plug->name = g_strdup(name); - new_plug->version = g_strdup(version); + new_plug->version = g_strdup(get_current_plugin_version()); + new_plug->spdx_id = g_strdup(get_current_plugin_spdx_id()); + new_plug->home_url = g_strdup(get_current_plugin_repository()); + new_plug->blurb = g_strdup(get_current_plugin_description()); new_plug->filename = g_strdup(filename); new_plug->scope = scope; new_plug->next = NULL; + + ws_debug("Lua plugin '%s' meta data: version = %s, flags = 0x0, spdx = %s, blurb = %s", + name, new_plug->version, new_plug->spdx_id, new_plug->blurb); } static void wslua_clear_plugin_list(void) @@ -739,8 +748,8 @@ static gboolean lua_load_plugin_script(const gchar* name, { ws_debug("Loading lua script: %s", filename); if (lua_load_script(filename, dirname, file_count)) { - wslua_add_plugin(name, get_current_plugin_version(), filename, scope); - clear_current_plugin_version(); + wslua_add_plugin(name, filename, scope); + clear_current_plugin_info(); return TRUE; } return FALSE; @@ -903,7 +912,7 @@ void wslua_plugins_get_descriptions(plugin_description_callback callback, void * for (lua_plug = wslua_plugin_list; lua_plug != NULL; lua_plug = lua_plug->next) { callback(lua_plug->name, lua_plug->version, - 0 /* flags */, "" /* spdx */, "" /* blurb */, "" /* home_url */, + 0 /* flags */, lua_plug->spdx_id, lua_plug->blurb, lua_plug->home_url, lua_plug->filename, lua_plug->scope, user_data); } } diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index 0f6a146ebe..5ba16f35e4 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -806,7 +806,10 @@ extern int wslua_hex2bin(lua_State* L, const char* data, const guint len, const extern int luaopen_rex_pcre2(lua_State *L); extern const gchar* get_current_plugin_version(void); -extern void clear_current_plugin_version(void); +extern const gchar* get_current_plugin_description(void); +extern const gchar* get_current_plugin_repository(void); +extern const gchar* get_current_plugin_spdx_id(void); +extern void clear_current_plugin_info(void); extern int wslua_deregister_heur_dissectors(lua_State* L); extern int wslua_deregister_protocols(lua_State* L); diff --git a/epan/wslua/wslua_utility.c b/epan/wslua/wslua_utility.c index 4bfa3be950..6aa693e608 100644 --- a/epan/wslua/wslua_utility.c +++ b/epan/wslua/wslua_utility.c @@ -28,17 +28,36 @@ WSLUA_FUNCTION wslua_get_version(lua_State* L) { /* Gets the Wireshark version a } -static gchar* current_plugin_version = NULL; +static gchar *current_plugin_version = NULL; +static gchar *current_plugin_description = NULL; +static gchar *current_plugin_repository = NULL; +static gchar *current_plugin_spdx_id = NULL; const gchar* get_current_plugin_version(void) { return current_plugin_version ? current_plugin_version : ""; } -void clear_current_plugin_version(void) { - if (current_plugin_version != NULL) { - g_free(current_plugin_version); - current_plugin_version = NULL; - } +const gchar* get_current_plugin_description(void) { + return current_plugin_description ? current_plugin_description : ""; +} + +const gchar* get_current_plugin_repository(void) { + return current_plugin_repository ? current_plugin_repository : ""; +} + +const gchar* get_current_plugin_spdx_id(void) { + return current_plugin_spdx_id ? current_plugin_spdx_id : ""; +} + +void clear_current_plugin_info(void) { + g_free(current_plugin_version); + current_plugin_version = NULL; + g_free(current_plugin_description); + current_plugin_description = NULL; + g_free(current_plugin_repository); + current_plugin_repository = NULL; + g_free(current_plugin_spdx_id); + current_plugin_spdx_id = NULL; } WSLUA_FUNCTION wslua_set_plugin_info(lua_State* L) { @@ -64,7 +83,9 @@ WSLUA_FUNCTION wslua_set_plugin_info(lua_State* L) { local my_info = { version = "1.0.1", author = "Jane Doe", - repository = "https://github.com/octocat/Spoon-Knife" + repository = "https://github.com/octocat/Spoon-Knife", + spdx_id = "GPL-2.0-or-later", + description = "Spoon-Knives can scoop and cut at the same time" } set_plugin_info(my_info) @@ -75,18 +96,18 @@ WSLUA_FUNCTION wslua_set_plugin_info(lua_State* L) { #define WSLUA_ARG_set_plugin_info_TABLE 1 /* The Lua table of information. */ if ( lua_istable(L,WSLUA_ARG_set_plugin_info_TABLE) ) { - int top; lua_getfield(L, WSLUA_ARG_set_plugin_info_TABLE, "version"); - top = lua_gettop(L); - if (lua_isstring(L, top)) { - clear_current_plugin_version(); - current_plugin_version = g_strdup( luaL_checkstring(L, top) ); - /* pop the string */ - lua_pop(L, 1); - } - else { + current_plugin_version = g_strdup(lua_tostring(L, -1)); + if (current_plugin_version == NULL) { return luaL_error(L,"the Lua table must have a 'version' key entry with a string value"); } + lua_getfield(L, WSLUA_ARG_set_plugin_info_TABLE, "description"); + current_plugin_description = g_strdup(lua_tostring(L, -1)); + lua_getfield(L, WSLUA_ARG_set_plugin_info_TABLE, "repository"); + current_plugin_repository = g_strdup(lua_tostring(L, -1)); + lua_getfield(L, WSLUA_ARG_set_plugin_info_TABLE, "spdx_id"); + current_plugin_spdx_id = g_strdup(lua_tostring(L, -1)); + lua_pop(L, 4); } else { return luaL_error(L,"a Lua table with at least a 'version' string entry"); } diff --git a/ui/qt/about_dialog.cpp b/ui/qt/about_dialog.cpp index 3f73fc1d1b..568fa1aa24 100644 --- a/ui/qt/about_dialog.cpp +++ b/ui/qt/about_dialog.cpp @@ -148,18 +148,18 @@ static void plugins_add_description(const char *name, const char *version, #ifdef HAVE_LUA // This exists only to add "lua script" to the type, otherwise we could use // plugins_add_description(). Eventually lua scripts -// should support plugin functional flags too (along with the other info fields) +// should support plugin functional flags too // and the "lua script" type can be dropped, or moved to // a new binary/lua/extcap type column (but not really). static void wslua_plugins_add_description(const char *name, const char *version, uint32_t flags _U_, const char *spdx_id _U_, - const char *blurb _U_, const char *home_url _U_, + const char *blurb, const char *home_url, const char *filename _U_, plugin_scope_e scope, void *user_data) { QList *plugin_data = (QList *)user_data; QStringList plugin_row = QStringList() << name << version << "lua script" - << scope_to_str(scope) << "" << ""; + << scope_to_str(scope) << blurb << home_url; *plugin_data << plugin_row; } #endif -- cgit v1.2.3