diff options
Diffstat (limited to 'epan/wslua')
42 files changed, 2685 insertions, 2187 deletions
diff --git a/epan/wslua/.clang-tidy b/epan/wslua/.clang-tidy new file mode 100644 index 00000000..84ea0537 --- /dev/null +++ b/epan/wslua/.clang-tidy @@ -0,0 +1,10 @@ +InheritParentConfig: true + +# We don't want to do any checks in this directory yet so hack around +# the fact that Clang-Tidy won't let us disable all checks. +# https://stackoverflow.com/a/58379342/82195 +Checks: + - '-*' + - 'misc-definitions-in-headers' +CheckOptions: + - { key: 'HeaderFileExtensions', value: 'DISABLED' } diff --git a/epan/wslua/CMakeLists.txt b/epan/wslua/CMakeLists.txt index c7d16e1c..9f35e148 100644 --- a/epan/wslua/CMakeLists.txt +++ b/epan/wslua/CMakeLists.txt @@ -114,7 +114,7 @@ add_library(wslua OBJECT ) if(FETCH_lua) - add_dependencies(wslua lua52) + add_dependencies(wslua lua54) endif() target_include_directories(wslua diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c index 3e701ffc..065eaf38 100644 --- a/epan/wslua/init_wslua.c +++ b/epan/wslua/init_wslua.c @@ -18,9 +18,7 @@ #include "wslua.h" #include "init_wslua.h" -#include <epan/dissectors/packet-frame.h> #include <errno.h> -#include <math.h> #include <stdio.h> #include <epan/expert.h> #include <epan/ex-opt.h> @@ -29,21 +27,22 @@ #include <wsutil/privileges.h> #include <wsutil/file_util.h> #include <wsutil/wslog.h> +#include <wsutil/array.h> /* linked list of Lua plugins */ typedef struct _wslua_plugin { - gchar *name; /**< plugin name */ - gchar *version; /**< plugin version */ - gchar *filename; /**< plugin filename */ + char *name; /**< plugin name */ + char *version; /**< plugin version */ + char *filename; /**< plugin filename */ struct _wslua_plugin *next; } wslua_plugin; -static wslua_plugin *wslua_plugin_list = NULL; +static wslua_plugin *wslua_plugin_list; -static lua_State* L = NULL; +static lua_State* L; -static void (*wslua_gui_print_func_ptr)(const char *, void *) = NULL; -static void *wslua_gui_print_data_ptr = NULL; +static void (*wslua_gui_print_func_ptr)(const char *, void *); +static void *wslua_gui_print_data_ptr; static int wslua_lua_print_func_ref = LUA_NOREF; /* XXX: global variables? Really?? Yuck. These could be done differently, @@ -54,98 +53,110 @@ tvbuff_t* lua_tvb; int lua_dissectors_table_ref = LUA_NOREF; int lua_heur_dissectors_table_ref = LUA_NOREF; -static int proto_lua = -1; - -static int hf_wslua_fake = -1; -static int hf_wslua_text = -1; - -static expert_field ei_lua_error = EI_INIT; - -static expert_field ei_lua_proto_checksum_comment = EI_INIT; -static expert_field ei_lua_proto_checksum_chat = EI_INIT; -static expert_field ei_lua_proto_checksum_note = EI_INIT; -static expert_field ei_lua_proto_checksum_warn = EI_INIT; -static expert_field ei_lua_proto_checksum_error = EI_INIT; - -static expert_field ei_lua_proto_sequence_comment = EI_INIT; -static expert_field ei_lua_proto_sequence_chat = EI_INIT; -static expert_field ei_lua_proto_sequence_note = EI_INIT; -static expert_field ei_lua_proto_sequence_warn = EI_INIT; -static expert_field ei_lua_proto_sequence_error = EI_INIT; - -static expert_field ei_lua_proto_response_comment = EI_INIT; -static expert_field ei_lua_proto_response_chat = EI_INIT; -static expert_field ei_lua_proto_response_note = EI_INIT; -static expert_field ei_lua_proto_response_warn = EI_INIT; -static expert_field ei_lua_proto_response_error = EI_INIT; - -static expert_field ei_lua_proto_request_comment = EI_INIT; -static expert_field ei_lua_proto_request_chat = EI_INIT; -static expert_field ei_lua_proto_request_note = EI_INIT; -static expert_field ei_lua_proto_request_warn = EI_INIT; -static expert_field ei_lua_proto_request_error = EI_INIT; - -static expert_field ei_lua_proto_undecoded_comment = EI_INIT; -static expert_field ei_lua_proto_undecoded_chat = EI_INIT; -static expert_field ei_lua_proto_undecoded_note = EI_INIT; -static expert_field ei_lua_proto_undecoded_warn = EI_INIT; -static expert_field ei_lua_proto_undecoded_error = EI_INIT; - -static expert_field ei_lua_proto_reassemble_comment = EI_INIT; -static expert_field ei_lua_proto_reassemble_chat = EI_INIT; -static expert_field ei_lua_proto_reassemble_note = EI_INIT; -static expert_field ei_lua_proto_reassemble_warn = EI_INIT; -static expert_field ei_lua_proto_reassemble_error = EI_INIT; - -static expert_field ei_lua_proto_malformed_comment = EI_INIT; -static expert_field ei_lua_proto_malformed_chat = EI_INIT; -static expert_field ei_lua_proto_malformed_note = EI_INIT; -static expert_field ei_lua_proto_malformed_warn = EI_INIT; -static expert_field ei_lua_proto_malformed_error = EI_INIT; - -static expert_field ei_lua_proto_debug_comment = EI_INIT; -static expert_field ei_lua_proto_debug_chat = EI_INIT; -static expert_field ei_lua_proto_debug_note = EI_INIT; -static expert_field ei_lua_proto_debug_warn = EI_INIT; -static expert_field ei_lua_proto_debug_error = EI_INIT; - -static expert_field ei_lua_proto_protocol_comment = EI_INIT; -static expert_field ei_lua_proto_protocol_chat = EI_INIT; -static expert_field ei_lua_proto_protocol_note = EI_INIT; -static expert_field ei_lua_proto_protocol_warn = EI_INIT; -static expert_field ei_lua_proto_protocol_error = EI_INIT; - -static expert_field ei_lua_proto_security_comment = EI_INIT; -static expert_field ei_lua_proto_security_chat = EI_INIT; -static expert_field ei_lua_proto_security_note = EI_INIT; -static expert_field ei_lua_proto_security_warn = EI_INIT; -static expert_field ei_lua_proto_security_error = EI_INIT; - -static expert_field ei_lua_proto_comments_comment = EI_INIT; -static expert_field ei_lua_proto_comments_chat = EI_INIT; -static expert_field ei_lua_proto_comments_note = EI_INIT; -static expert_field ei_lua_proto_comments_warn = EI_INIT; -static expert_field ei_lua_proto_comments_error = EI_INIT; - -static expert_field ei_lua_proto_decryption_comment = EI_INIT; -static expert_field ei_lua_proto_decryption_chat = EI_INIT; -static expert_field ei_lua_proto_decryption_note = EI_INIT; -static expert_field ei_lua_proto_decryption_warn = EI_INIT; -static expert_field ei_lua_proto_decryption_error = EI_INIT; - -static expert_field ei_lua_proto_assumption_comment = EI_INIT; -static expert_field ei_lua_proto_assumption_chat = EI_INIT; -static expert_field ei_lua_proto_assumption_note = EI_INIT; -static expert_field ei_lua_proto_assumption_warn = EI_INIT; -static expert_field ei_lua_proto_assumption_error = EI_INIT; - -static expert_field ei_lua_proto_deprecated_comment = EI_INIT; -static expert_field ei_lua_proto_deprecated_chat = EI_INIT; -static expert_field ei_lua_proto_deprecated_note = EI_INIT; -static expert_field ei_lua_proto_deprecated_warn = EI_INIT; -static expert_field ei_lua_proto_deprecated_error = EI_INIT; - -static gint ett_wslua_traceback = -1; +static int proto_lua; + +static int hf_wslua_fake; +static int hf_wslua_text; + +static expert_field ei_lua_error; + +static expert_field ei_lua_proto_checksum_comment; +static expert_field ei_lua_proto_checksum_chat; +static expert_field ei_lua_proto_checksum_note; +static expert_field ei_lua_proto_checksum_warn; +static expert_field ei_lua_proto_checksum_error; + +static expert_field ei_lua_proto_sequence_comment; +static expert_field ei_lua_proto_sequence_chat; +static expert_field ei_lua_proto_sequence_note; +static expert_field ei_lua_proto_sequence_warn; +static expert_field ei_lua_proto_sequence_error; + +static expert_field ei_lua_proto_response_comment; +static expert_field ei_lua_proto_response_chat; +static expert_field ei_lua_proto_response_note; +static expert_field ei_lua_proto_response_warn; +static expert_field ei_lua_proto_response_error; + +static expert_field ei_lua_proto_request_comment; +static expert_field ei_lua_proto_request_chat; +static expert_field ei_lua_proto_request_note; +static expert_field ei_lua_proto_request_warn; +static expert_field ei_lua_proto_request_error; + +static expert_field ei_lua_proto_undecoded_comment; +static expert_field ei_lua_proto_undecoded_chat; +static expert_field ei_lua_proto_undecoded_note; +static expert_field ei_lua_proto_undecoded_warn; +static expert_field ei_lua_proto_undecoded_error; + +static expert_field ei_lua_proto_reassemble_comment; +static expert_field ei_lua_proto_reassemble_chat; +static expert_field ei_lua_proto_reassemble_note; +static expert_field ei_lua_proto_reassemble_warn; +static expert_field ei_lua_proto_reassemble_error; + +static expert_field ei_lua_proto_malformed_comment; +static expert_field ei_lua_proto_malformed_chat; +static expert_field ei_lua_proto_malformed_note; +static expert_field ei_lua_proto_malformed_warn; +static expert_field ei_lua_proto_malformed_error; + +static expert_field ei_lua_proto_debug_comment; +static expert_field ei_lua_proto_debug_chat; +static expert_field ei_lua_proto_debug_note; +static expert_field ei_lua_proto_debug_warn; +static expert_field ei_lua_proto_debug_error; + +static expert_field ei_lua_proto_protocol_comment; +static expert_field ei_lua_proto_protocol_chat; +static expert_field ei_lua_proto_protocol_note; +static expert_field ei_lua_proto_protocol_warn; +static expert_field ei_lua_proto_protocol_error; + +static expert_field ei_lua_proto_security_comment; +static expert_field ei_lua_proto_security_chat; +static expert_field ei_lua_proto_security_note; +static expert_field ei_lua_proto_security_warn; +static expert_field ei_lua_proto_security_error; + +static expert_field ei_lua_proto_comments_comment; +static expert_field ei_lua_proto_comments_chat; +static expert_field ei_lua_proto_comments_note; +static expert_field ei_lua_proto_comments_warn; +static expert_field ei_lua_proto_comments_error; + +static expert_field ei_lua_proto_decryption_comment; +static expert_field ei_lua_proto_decryption_chat; +static expert_field ei_lua_proto_decryption_note; +static expert_field ei_lua_proto_decryption_warn; +static expert_field ei_lua_proto_decryption_error; + +static expert_field ei_lua_proto_assumption_comment; +static expert_field ei_lua_proto_assumption_chat; +static expert_field ei_lua_proto_assumption_note; +static expert_field ei_lua_proto_assumption_warn; +static expert_field ei_lua_proto_assumption_error; + +static expert_field ei_lua_proto_deprecated_comment; +static expert_field ei_lua_proto_deprecated_chat; +static expert_field ei_lua_proto_deprecated_note; +static expert_field ei_lua_proto_deprecated_warn; +static expert_field ei_lua_proto_deprecated_error; + +static expert_field ei_lua_proto_receive_comment; +static expert_field ei_lua_proto_receive_chat; +static expert_field ei_lua_proto_receive_note; +static expert_field ei_lua_proto_receive_warn; +static expert_field ei_lua_proto_receive_error; + +static expert_field ei_lua_proto_interface_comment; +static expert_field ei_lua_proto_interface_chat; +static expert_field ei_lua_proto_interface_note; +static expert_field ei_lua_proto_interface_warn; +static expert_field ei_lua_proto_interface_error; + +static int ett_wslua_traceback; static bool lua_pinfo_end(wmem_allocator_t *allocator _U_, wmem_cb_event_t event _U_, @@ -162,7 +173,7 @@ lua_pinfo_end(wmem_allocator_t *allocator _U_, wmem_cb_event_t event _U_, clear_outstanding_FuncSavers(); /* keep invoking this callback later? */ - return FALSE; + return false; } static int wslua_not_register_menu(lua_State* LS) { @@ -175,7 +186,7 @@ int get_hf_wslua_text(void) { return hf_wslua_text; } -#if LUA_VERSION_NUM >= 502 + // Attach the lua traceback to the proto_tree static int dissector_error_handler(lua_State *LS) { // Entering, stack: [ error_handler, dissector, errmsg ] @@ -259,18 +270,6 @@ static int dissector_error_handler(lua_State *LS) { return -2; } -#else - -static int dissector_error_handler(lua_State *LS) { - // Entering, stack: [ error_handler, dissector, errmsg ] - proto_tree_add_expert_format(lua_tree->tree, lua_pinfo, &ei_lua_error, lua_tvb, 0, 0, - "Lua Error: %s", lua_tostring(LS,-1)); - - // Return the same error message - return -1; -} - -#endif int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_) { int consumed_bytes = tvb_captured_length(tvb); @@ -326,7 +325,7 @@ int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data /* if the Lua dissector reported the consumed bytes, pass it to our caller */ if (lua_isnumber(L, -1)) { /* we got the consumed bytes or the missing bytes as a negative number */ - consumed_bytes = wslua_togint(L, -1); + consumed_bytes = wslua_toint(L, -1); lua_pop(L, 1); } } @@ -351,10 +350,10 @@ int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data * @param tvb the tvbuff with the (remaining) packet data * @param pinfo the packet info of this packet (additional info) * @param tree the protocol tree to be build or NULL - * @return TRUE if the packet was recognized by the sub-dissector (stop dissection here) + * @return true if the packet was recognized by the sub-dissector (stop dissection here) */ -gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_) { - gboolean result = FALSE; +bool heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_) { + bool result = false; tvbuff_t *saved_lua_tvb = lua_tvb; packet_info *saved_lua_pinfo = lua_pinfo; struct _wslua_treeitem *saved_lua_tree = lua_tree; @@ -366,7 +365,7 @@ gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, v if (!pinfo->heur_list_name || !pinfo->current_proto) { proto_tree_add_expert_format(tree, pinfo, &ei_lua_error, tvb, 0, 0, "internal error in heur_dissect_lua: NULL list name or current proto"); - return FALSE; + return false; } /* heuristic functions are stored in a table in the registry; the registry has a @@ -387,7 +386,7 @@ gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, v lua_settop(L,0); proto_tree_add_expert_format(tree, pinfo, &ei_lua_error, tvb, 0, 0, "internal error in heur_dissect_lua: no %s heur list table", pinfo->heur_list_name); - return FALSE; + return false; } /* get the table inside that, for the specific lua heuristic dissector */ @@ -397,7 +396,7 @@ gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, v proto_tree_add_expert_format(tree, pinfo, &ei_lua_error, tvb, 0, 0, "internal error in heur_dissect_lua: no %s heuristic dissector for list %s", pinfo->current_proto, pinfo->heur_list_name); - return FALSE; + return false; } /* remove the table of all lists (the one in the registry) */ @@ -410,7 +409,7 @@ gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, v lua_settop(L,0); proto_tree_add_expert_format(tree, pinfo, &ei_lua_error, tvb, 0, 0, "internal error in heur_dissect_lua: %s heuristic dissector is not a function", pinfo->current_proto); - return FALSE; + return false; } push_Tvb(L,tvb); @@ -426,7 +425,7 @@ gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, v if (lua_isboolean(L, -1) || lua_isnil(L, -1)) { result = lua_toboolean(L, -1); } else if (lua_type(L, -1) == LUA_TNUMBER) { - result = lua_tointeger(L,-1) != 0 ? TRUE : FALSE; + result = lua_tointeger(L,-1) != 0 ? true : false; } else { proto_tree_add_expert_format(tree, pinfo, &ei_lua_error, tvb, 0, 0, "Lua Error: invalid return value from Lua %s heuristic dissector", pinfo->current_proto); @@ -443,7 +442,7 @@ gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, v return result; } -static void iter_table_and_call(lua_State* LS, const gchar* table_name, lua_CFunction error_handler) { +static void iter_table_and_call(lua_State* LS, const char* table_name, lua_CFunction error_handler) { lua_settop(LS,0); lua_pushcfunction(LS,error_handler); @@ -459,7 +458,7 @@ static void iter_table_and_call(lua_State* LS, const gchar* table_name, lua_CFun lua_pushnil(LS); while (lua_next(LS, 2)) { - const gchar* name = lua_tostring(L,-2); + const char* name = lua_tostring(L,-2); if (lua_isfunction(LS,-1)) { @@ -480,13 +479,13 @@ static void iter_table_and_call(lua_State* LS, const gchar* table_name, lua_CFun static int init_error_handler(lua_State* LS) { - const gchar* error = lua_tostring(LS,1); + const char* error = lua_tostring(LS,1); report_failure("Lua: Error during execution of initialization:\n %s",error); return 0; } -static gboolean init_routine_initialized = FALSE; +static bool init_routine_initialized; static void wslua_init_routine(void) { if ( ! init_routine_initialized ) { @@ -501,7 +500,7 @@ static void wslua_init_routine(void) { * Lua states, we'll need to change this. */ lua_prime_all_fields(NULL); - init_routine_initialized = TRUE; + init_routine_initialized = true; } if (L) { @@ -517,7 +516,7 @@ static void wslua_cleanup_routine(void) { } static int prefs_changed_error_handler(lua_State* LS) { - const gchar* error = lua_tostring(LS,1); + const char* error = lua_tostring(LS,1); report_failure("Lua: Error during execution of prefs apply callback:\n %s",error); return 0; } @@ -538,18 +537,13 @@ static const char *getF(lua_State *LS _U_, void *ud, size_t *size) } static int error_handler_with_callback(lua_State *LS) { -#if LUA_VERSION_NUM >= 502 const char *msg = lua_tostring(LS, 1); luaL_traceback(LS, LS, msg, 1); /* push message with traceback. */ lua_remove(LS, -2); /* remove original msg */ -#else - /* Return error message, unmodified */ - (void)LS; -#endif return 1; } -static void wslua_add_plugin(const gchar *name, const gchar *version, const gchar *filename) +static void wslua_add_plugin(const char *name, const char *version, const char *filename) { wslua_plugin *new_plug, *lua_plug; @@ -586,8 +580,8 @@ static void wslua_clear_plugin_list(void) } static int lua_script_push_args(const int script_num) { - gchar* argname = ws_strdup_printf("lua_script%d", script_num); - const gchar* argvalue = NULL; + char* argname = ws_strdup_printf("lua_script%d", script_num); + const char* argvalue = NULL; int i, count = ex_opt_count(argname); for (i = 0; i < count; i++) { @@ -599,67 +593,134 @@ static int lua_script_push_args(const int script_num) { return count; } +/* Prepends a path to the global package path (used by require) + * We could add a custom loader to package.searchers instead, which + * might be more useful in some way. We could also have some method of + * saving and restoring the path, instead of constantly adding to it. */ +static void prepend_path(const char* dirname) { + const char* path; + + /* prepend the directory name to _G.package.path */ + lua_getglobal(L, "package"); /* get the package table from the global table */ + lua_getfield(L, -1, "path"); /* get the path field from the package table */ + path = luaL_checkstring(L, -1); /* get the path string */ + lua_pop(L, 1); /* pop the path string */ + /* prepend the path */ + /* We could also add "?/init.lua" for packages. */ + lua_pushfstring(L, "%s" G_DIR_SEPARATOR_S "?.lua;%s", + dirname, path); + lua_setfield(L, -2, "path"); + lua_pop(L, 1); +} + #define FILE_NAME_KEY "__FILE__" #define DIR_NAME_KEY "__DIR__" #define DIR_SEP_NAME_KEY "__DIR_SEPARATOR__" /* assumes a loaded chunk's function is on top of stack */ -static void set_file_environment(const gchar* filename, const gchar* dirname) { - const char* path; - +static void set_file_environment(const char* filename, const char* dirname) { lua_newtable(L); /* environment for script (index 3) */ + /* XXX - Do we need this? A script can get the filename and path from + * debug.getinfo/lua_Debug source */ lua_pushstring(L, filename); /* tell the script about its filename */ lua_setfield(L, -2, FILE_NAME_KEY); /* make it accessible at __FILE__ */ lua_pushstring(L, dirname); /* tell the script about its dirname */ lua_setfield(L, -2, DIR_NAME_KEY); /* make it accessible at __DIR__ */ + /* XXX - Do we need this? package.config:sub(1,1) is the directory separator */ lua_pushstring(L, G_DIR_SEPARATOR_S); /* tell the script the directory separator */ - lua_setfield(L, -2, DIR_SEP_NAME_KEY); /* make it accessible at __DIR__ */ + lua_setfield(L, -2, DIR_SEP_NAME_KEY); /* make it accessible at __DIR_SEPARATOR__ */ lua_newtable(L); /* new metatable */ -#if LUA_VERSION_NUM >= 502 lua_pushglobaltable(L); -#else - lua_pushvalue(L, LUA_GLOBALSINDEX); -#endif - /* prepend the directory name to _G.package.path */ - lua_getfield(L, -1, "package"); /* get the package table from the global table */ - lua_getfield(L, -1, "path"); /* get the path field from the package table */ - path = luaL_checkstring(L, -1); /* get the path string */ - lua_pop(L, 1); /* pop the path string */ - /* prepend the various paths */ - lua_pushfstring(L, "%s" G_DIR_SEPARATOR_S "?.lua;%s" G_DIR_SEPARATOR_S "?.lua;%s" G_DIR_SEPARATOR_S "?.lua;%s", - dirname, get_plugins_pers_dir(), get_plugins_dir(), path); - lua_setfield(L, -2, "path"); /* set the new string to be the path field of the package table */ - lua_setfield(L, -2, "package"); /* set the package table to be the package field of the global */ lua_setfield(L, -2, "__index"); /* make metatable's __index point to global table */ lua_setmetatable(L, -2); /* pop metatable, set it as metatable of environment */ -#if LUA_VERSION_NUM >= 502 lua_setupvalue(L, -2, 1); /* pop environment and assign it to upvalue 1 */ -#else - lua_setfenv(L, -2); /* pop environment and set it as the func's environment */ -#endif + + /* The result of this is a new environment that falls back to reading from + * the global environment for any entry not in the new environment, but + * can't change the global environment while running. + * + * Unfortunately, while we could create a file-local package.path, it + * wouldn't have any effect on the path actually used by requires, since + * the requires function has as an upvalue the original package table; + * we can't change the behavior of requires without changing it for + * the global environment and for all scripts. + * + * For some of the same reasons, if the script itself calls require(), + * that actually affects the original global environment too, so this + * sandboxing doesn't completely work to keep the global environment + * unchanged. Is it worth it? + */ } +/* This loads plugins like Lua modules / libraries, using require(). + * It has the advantage that loaded files get add to the package.loaded + * table, so files aren't run again by require() either. + */ +static bool lua_load_plugin(const char* filename) { + int status; + char *trimmed; + + const char *basename = get_basename(filename); + char *dot = strrchr(basename, '.'); + if (dot) { + trimmed = g_strndup(basename, dot - basename); + } else { + trimmed = g_strdup(basename); + } + + lua_settop(L, 0); + + lua_pushcfunction(L, error_handler_with_callback); + + lua_getglobal(L, "require"); + + lua_pushstring(L, trimmed); + g_free(trimmed); + + /* Ignore the return from "require" by passing 0 as nresults to lua_pcall + * (we could add it to the global table using the name as dolibrary() does, + * but that is deprecated style in modern Lua.) + */ + status = lua_pcall(L, 1, 0, 1); + if (status != LUA_OK) { + switch (status) { + case LUA_ERRRUN: + report_failure("Lua: Error during loading:\n%s", lua_tostring(L, -1)); + break; + case LUA_ERRMEM: + report_failure("Lua: Error during loading: out of memory"); + break; + case LUA_ERRERR: + report_failure("Lua: Error during loading: error while retrieving error message"); + break; + default: + report_failure("Lua: Error during loading: unknown error %d", status); + break; + } + } + return status == LUA_OK; +} /* If file_count > 0 then it's a command-line-added user script, and the count * represents which user script it is (first=1, second=2, etc.). * If dirname != NULL, then it's a user script and the dirname will get put in a file environment * If dirname == NULL then it's a wireshark script and no file environment is created */ -static gboolean lua_load_script(const gchar* filename, const gchar* dirname, const int file_count) { +static bool lua_load_script(const char* filename, const char* dirname, const int file_count) { FILE* file; int error; int numargs = 0; if (! ( file = ws_fopen(filename,"r")) ) { - report_open_failure(filename,errno,FALSE); - return FALSE; + report_open_failure(filename,errno,false); + return false; } lua_settop(L,0); @@ -668,11 +729,7 @@ static gboolean lua_load_script(const gchar* filename, const gchar* dirname, con /* The source argument should start with '@' to indicate a file. */ lua_pushfstring(L, "@%s", filename); -#if LUA_VERSION_NUM >= 502 error = lua_load(L, getF, file, lua_tostring(L, -1), NULL); -#else - error = lua_load(L, getF, file, lua_tostring(L, -1)); -#endif switch (error) { case 0: /* LUA_OK */ @@ -721,25 +778,26 @@ static gboolean lua_load_script(const gchar* filename, const gchar* dirname, con /* This one is used to load the init.lua scripts, or anything else * that shouldn't really be considered a real plugin. */ -static gboolean lua_load_internal_script(const gchar* filename) { +static bool lua_load_internal_script(const char* filename) { return lua_load_script(filename, NULL, 0); } -/* This one is used to load plugins: either from the plugin directories, - * or from the command line. +/* This one is used to load plugins from the plugin directories, + * or scripts from the command line. The latter have file_count > 0. */ -static gboolean lua_load_plugin_script(const gchar* name, - const gchar* filename, - const gchar* dirname, - const int file_count) +static bool lua_load_plugin_script(const char* name, + const char* filename, + const char* dirname, + const int file_count) { ws_debug("Loading lua script: %s", filename); - if (lua_load_script(filename, dirname, file_count)) { + if (file_count > 0 ? lua_load_script(filename, dirname, file_count) : + lua_load_plugin(filename)) { wslua_add_plugin(name, get_current_plugin_version(), filename); clear_current_plugin_version(); - return TRUE; + return true; } - return FALSE; + return false; } static int wslua_panic(lua_State* LS) { @@ -748,18 +806,18 @@ static int wslua_panic(lua_State* LS) { return 0; /* keep gcc happy */ } -static gint string_compare(gconstpointer a, gconstpointer b) { +static int string_compare(const void *a, const void *b) { return strcmp((const char*)a, (const char*)b); } -static int lua_load_plugins(const char *dirname, register_cb cb, gpointer client_data, - gboolean count_only, const gboolean is_user, GHashTable *loaded_files, +static int lua_load_plugins(const char *dirname, register_cb cb, void *client_data, + bool count_only, const bool is_user, GHashTable *loaded_files, int depth) { WS_DIR *dir; /* scanned directory */ WS_DIRENT *file; /* current file */ - gchar *filename, *dot; - const gchar *name; + char *filename, *dot; + const char *name; int plugins_counter = 0; GList *sorted_dirnames = NULL; GList *sorted_filenames = NULL; @@ -783,11 +841,11 @@ static int lua_load_plugins(const char *dirname, register_cb cb, gpointer client filename = ws_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", dirname, name); if (test_for_directory(filename) == EISDIR) { - sorted_dirnames = g_list_prepend(sorted_dirnames, (gpointer)filename); + sorted_dirnames = g_list_prepend(sorted_dirnames, (void *)filename); continue; } - /* skip files starting wih . */ + /* skip files starting with . */ if (name[0] == '.') { g_free(filename); continue; @@ -801,7 +859,7 @@ static int lua_load_plugins(const char *dirname, register_cb cb, gpointer client } if (file_exists(filename)) { - sorted_filenames = g_list_prepend(sorted_filenames, (gpointer)filename); + sorted_filenames = g_list_prepend(sorted_filenames, (void *)filename); } else { g_free(filename); @@ -821,9 +879,14 @@ static int lua_load_plugins(const char *dirname, register_cb cb, gpointer client /* Process files in ASCIIbetical order */ if (sorted_filenames != NULL) { + /* If this is not the root of the plugin directory, add it to the path. + * XXX - Should we remove it after we're done with this directory? */ + if (depth > 0) { + prepend_path(dirname); + } sorted_filenames = g_list_sort(sorted_filenames, string_compare); for (l = sorted_filenames; l != NULL; l = l->next) { - filename = (gchar *)l->data; + filename = (char *)l->data; name = strrchr(filename, G_DIR_SEPARATOR) + 1; /* Check if we have already loaded this file name, if provided with a set */ @@ -848,27 +911,32 @@ static int lua_load_plugins(const char *dirname, register_cb cb, gpointer client return plugins_counter; } -static int lua_load_global_plugins(register_cb cb, gpointer client_data, - gboolean count_only) +static int lua_load_global_plugins(register_cb cb, void *client_data, + bool count_only) { - return lua_load_plugins(get_plugins_dir(), cb, client_data, count_only, FALSE, NULL, 0); + return lua_load_plugins(get_plugins_dir(), cb, client_data, count_only, false, NULL, 0); } -static int lua_load_pers_plugins(register_cb cb, gpointer client_data, - gboolean count_only) +static int lua_load_pers_plugins(register_cb cb, void *client_data, + bool count_only) { int plugins_counter = 0; /* aux table (set) to make sure we only load each file once (by name) */ + /* XXX - This doesn't prevent users from loading a file a second time + * via a different method, e.g., require() or dofile(). + * + * It shouldn't be needed now that we're calling require for the plugins. + */ GHashTable *loaded_user_scripts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); /* load user scripts */ - plugins_counter += lua_load_plugins(get_plugins_pers_dir(), cb, client_data, count_only, TRUE, loaded_user_scripts, 0); + plugins_counter += lua_load_plugins(get_plugins_pers_dir(), cb, client_data, count_only, true, loaded_user_scripts, 0); /* for backward compatibility check old plugin directory */ - char *old_path = get_persconffile_path("plugins", FALSE); + char *old_path = get_persconffile_path("plugins", false); if (strcmp(get_plugins_pers_dir(), old_path) != 0) { - plugins_counter += lua_load_plugins(old_path, cb, client_data, count_only, TRUE, loaded_user_scripts, 0); + plugins_counter += lua_load_plugins(old_path, cb, client_data, count_only, true, loaded_user_scripts, 0); } g_free(old_path); @@ -881,10 +949,10 @@ int wslua_count_plugins(void) { int plugins_counter; /* count global scripts */ - plugins_counter = lua_load_global_plugins(NULL, NULL, TRUE); + plugins_counter = lua_load_global_plugins(NULL, NULL, true); /* count user scripts */ - plugins_counter += lua_load_pers_plugins(NULL, NULL, TRUE); + plugins_counter += lua_load_pers_plugins(NULL, NULL, true); /* count scripts from command line */ plugins_counter += ex_opt_count("lua_script"); @@ -920,8 +988,8 @@ const char *wslua_plugin_type_name(void) { return "lua script"; } -static ei_register_info* ws_lua_ei = NULL; -static int ws_lua_ei_len = 0; +static ei_register_info* ws_lua_ei; +static int ws_lua_ei_len; expert_field* wslua_get_expert_field(const int group, const int severity) @@ -969,7 +1037,7 @@ add_table_symbol(const char *table, const char *name, int value) lua_getglobal(L, table); /* Set symbol in table. */ lua_pushstring(L, name); - lua_pushnumber(L, value); + lua_pushinteger(L, value); lua_settable(L, -3); /* Pop table from stack. */ lua_pop(L, 1); @@ -979,7 +1047,7 @@ static void add_global_symbol(const char *name, int value) { /* Set symbol in global environment. */ - lua_pushnumber(L, value); + lua_pushinteger(L, value); lua_setglobal(L, name); } @@ -988,7 +1056,7 @@ add_pi_severity_symbol(const char *name, int value) { lua_getglobal(L, WSLUA_EXPERT_TABLE); lua_getfield(L, -1, WSLUA_EXPERT_SEVERITY_TABLE); - lua_pushnumber(L, value); + lua_pushinteger(L, value); lua_setfield(L, -2, name); lua_pop(L, 2); } @@ -998,7 +1066,7 @@ add_pi_group_symbol(const char *name, int value) { lua_getglobal(L, WSLUA_EXPERT_TABLE); lua_getfield(L, -1, WSLUA_EXPERT_GROUP_TABLE); - lua_pushnumber(L, value); + lua_pushinteger(L, value); lua_setfield(L, -2, name); lua_pop(L, 2); } @@ -1007,11 +1075,13 @@ static void add_menu_group_symbol(const char *name, int value) { /* Set symbol in global environment. */ - lua_pushnumber(L, value); + lua_pushinteger(L, value); char *str = g_strdup(name); char *s = strstr(str, "_GROUP_"); - if (s == NULL) + if (s == NULL) { + g_free(str); return; + } *s = '\0'; s += strlen("_GROUP_"); char *str2 = ws_strdup_printf("MENU_%s_%s", str, s); @@ -1152,6 +1222,18 @@ static void wslua_add_deprecated(void) lua_setglobal(L, "MENU_STAT_RESPONSE"); lua_getglobal(L, "MENU_PACKET_STAT_UNSORTED"); lua_setglobal(L, "MENU_STAT_UNSORTED"); + lua_getglobal(L, "MENU_TELEPHONY_UNSORTED"); + lua_setglobal(L, "MENU_STAT_TELEPHONY"); + lua_getglobal(L, "MENU_TELEPHONY_ANSI"); + lua_setglobal(L, "MENU_STAT_TELEPHONY_ANSI"); + lua_getglobal(L, "MENU_TELEPHONY_GSM"); + lua_setglobal(L, "MENU_STAT_TELEPHONY_GSM"); + lua_getglobal(L, "MENU_TELEPHONY_3GPP_UU"); + lua_setglobal(L, "MENU_STAT_TELEPHONY_3GPP_UU"); + lua_getglobal(L, "MENU_TELEPHONY_MTP3"); + lua_setglobal(L, "MENU_STAT_TELEPHONY_MTP3"); + lua_getglobal(L, "MENU_TELEPHONY_SCTP"); + lua_setglobal(L, "MENU_STAT_TELEPHONY_SCTP"); /* deprecated function names */ lua_getglobal(L, "Dir"); @@ -1179,10 +1261,6 @@ static const char *lua_error_msg(int code) return "unknown error"; } -#if LUA_VERSION_NUM == 501 -#define LUA_OK 0 -#endif - static int lua_funnel_console_eval(const char *console_input, char **error_ptr, char **error_hint, @@ -1246,6 +1324,20 @@ static int lua_funnel_console_eval(const char *console_input, } } + // For any new Protos, register their ProtoFields and ProtoExperts with epan + lua_pushcfunction(L, Proto_commit); + lcode = lua_pcall(L, 0, 0, 0); + if (lcode != LUA_OK) { + /* Error initializing new ProtoFields */ + if (error_hint) + *error_hint = ws_strdup_printf("error initialzing protocol fields: %s", lua_error_msg(lcode)); + /* If we have an error message return it. */ + if (error_ptr && !lua_isnil(L, -1)) { + *error_ptr = g_strdup(lua_tostring(L, -1)); + } + return 1; + } + // Maintain stack discipline if (lua_gettop(L) != curr_top) { ws_critical("Expected stack top == %d, have %d", curr_top, lua_gettop(L)); @@ -1255,30 +1347,6 @@ static int lua_funnel_console_eval(const char *console_input, return 0; } -#if LUA_VERSION_NUM == 501 -static const char *luaL_tolstring (lua_State *_L, int idx, size_t *len) { - if (!luaL_callmeta(_L, idx, "__tostring")) { /* no metafield? */ - switch (lua_type(_L, idx)) { - case LUA_TNUMBER: - case LUA_TSTRING: - lua_pushvalue(_L, idx); - break; - case LUA_TBOOLEAN: - lua_pushstring(_L, (lua_toboolean(_L, idx) ? "true" : "false")); - break; - case LUA_TNIL: - lua_pushliteral(_L, "nil"); - break; - default: - lua_pushfstring(_L, "%s: %p", luaL_typename(_L, idx), - lua_topointer(_L, idx)); - break; - } - } - return lua_tolstring(_L, -1, len); -} -#endif /* LUA_VERSION_NUM == 501 */ - /* Receives C print function pointer as first upvalue. */ /* Receives C print function data pointer as second upvalue. */ static int wslua_console_print(lua_State *_L) @@ -1372,7 +1440,7 @@ void wslua_add_useful_constants(void) lua_setglobal(L, "DATA_DIR"); /* USER_DIR has a trailing directory separator. */ - path = get_persconffile_path("", FALSE); + path = get_persconffile_path("", false); lua_pushfstring(L, "%s"G_DIR_SEPARATOR_S, path); g_free(path); lua_setglobal(L, "USER_DIR"); @@ -1384,13 +1452,13 @@ void wslua_add_useful_constants(void) lua_setglobal(L, "typeof"); } -void wslua_init(register_cb cb, gpointer client_data) { - gchar* filename; - gboolean enable_lua = TRUE; - gboolean run_anyway = FALSE; +void wslua_init(register_cb cb, void *client_data) { + char* filename; + bool enable_lua = true; + bool run_anyway = false; expert_module_t* expert_lua; int file_count = 1; - static gboolean first_time = TRUE; + static bool first_time = true; int i; int error; @@ -1403,7 +1471,7 @@ void wslua_init(register_cb cb, gpointer client_data) { { "Wireshark Lua text", "_ws.lua.text", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }}, }; - static gint *ett[] = { + static int *ett[] = { &ett_wslua_traceback, }; @@ -1501,6 +1569,18 @@ void wslua_init(register_cb cb, gpointer client_data) { { &ei_lua_proto_deprecated_warn, { "_ws.lua.proto.warning", PI_DEPRECATED, PI_WARN ,"Protocol Warning", EXPFILL }}, { &ei_lua_proto_deprecated_error, { "_ws.lua.proto.error", PI_DEPRECATED, PI_ERROR ,"Protocol Error", EXPFILL }}, + { &ei_lua_proto_receive_comment, { "_ws.lua.proto.comment", PI_RECEIVE, PI_COMMENT ,"Protocol Comment", EXPFILL }}, + { &ei_lua_proto_receive_chat, { "_ws.lua.proto.chat", PI_RECEIVE, PI_CHAT ,"Protocol Chat", EXPFILL }}, + { &ei_lua_proto_receive_note, { "_ws.lua.proto.note", PI_RECEIVE, PI_NOTE ,"Protocol Note", EXPFILL }}, + { &ei_lua_proto_receive_warn, { "_ws.lua.proto.warning", PI_RECEIVE, PI_WARN ,"Protocol Warning", EXPFILL }}, + { &ei_lua_proto_receive_error, { "_ws.lua.proto.error", PI_RECEIVE, PI_ERROR ,"Protocol Error", EXPFILL }}, + + { &ei_lua_proto_interface_comment, { "_ws.lua.proto.comment", PI_INTERFACE, PI_COMMENT ,"Protocol Comment", EXPFILL }}, + { &ei_lua_proto_interface_chat, { "_ws.lua.proto.chat", PI_INTERFACE, PI_CHAT ,"Protocol Chat", EXPFILL }}, + { &ei_lua_proto_interface_note, { "_ws.lua.proto.note", PI_INTERFACE, PI_NOTE ,"Protocol Note", EXPFILL }}, + { &ei_lua_proto_interface_warn, { "_ws.lua.proto.warning", PI_INTERFACE, PI_WARN ,"Protocol Warning", EXPFILL }}, + { &ei_lua_proto_interface_error, { "_ws.lua.proto.error", PI_INTERFACE, PI_ERROR ,"Protocol Error", EXPFILL }}, + /* this one is for reporting errors executing Lua code */ { &ei_lua_error, { "_ws.lua.error", PI_UNDECODED, PI_ERROR ,"Lua Error", EXPFILL }}, }; @@ -1516,14 +1596,6 @@ void wslua_init(register_cb cb, gpointer client_data) { WSLUA_INIT(L); -#if LUA_VERSION_NUM == 501 - /* table.unpack was introduced with Lua 5.2, alias it to unpack. */ - lua_getglobal(L, "table"); - lua_getglobal(L, "unpack"); - lua_setfield(L, -2, "unpack"); - lua_pop(L, 1); -#endif - if (first_time) { proto_lua = proto_register_protocol("Lua Dissection", "Lua Dissection", "_ws.lua"); proto_register_field_array(proto_lua, hf, array_length(hf)); @@ -1576,12 +1648,12 @@ void wslua_init(register_cb cb, gpointer client_data) { /* special constant used by PDU reassembly handling */ /* see dissect_lua() for notes */ - WSLUA_REG_GLOBAL_NUMBER(L,"DESEGMENT_ONE_MORE_SEGMENT",DESEGMENT_ONE_MORE_SEGMENT); + WSLUA_REG_GLOBAL_INTEGER(L,"DESEGMENT_ONE_MORE_SEGMENT",DESEGMENT_ONE_MORE_SEGMENT); /* the possible values for Pinfo's p2p_dir attribute */ - WSLUA_REG_GLOBAL_NUMBER(L,"P2P_DIR_UNKNOWN",-1); - WSLUA_REG_GLOBAL_NUMBER(L,"P2P_DIR_SENT",0); - WSLUA_REG_GLOBAL_NUMBER(L,"P2P_DIR_RECV",1); + WSLUA_REG_GLOBAL_INTEGER(L,"P2P_DIR_UNKNOWN",-1); + WSLUA_REG_GLOBAL_INTEGER(L,"P2P_DIR_SENT",0); + WSLUA_REG_GLOBAL_INTEGER(L,"P2P_DIR_RECV",1); wslua_add_introspection(); @@ -1603,6 +1675,14 @@ void wslua_init(register_cb cb, gpointer client_data) { } /* load system's init.lua */ +#if 0 + /* wslua_dofile / wslua_get_actual_filename look in the datafile dir. + * Should we add that to the path for require() as well, for consistency? + */ + prepend_path(get_datafile_dir()); +#endif + /* Add the global plugins path for require */ + prepend_path(get_plugins_dir()); filename = g_build_filename(get_plugins_dir(), "init.lua", (char *)NULL); if (file_exists(filename)) { ws_debug("Loading init.lua file: %s", filename); @@ -1613,6 +1693,21 @@ void wslua_init(register_cb cb, gpointer client_data) { /* load user's init.lua */ /* if we are indeed superuser run user scripts only if told to do so */ if (!started_with_special_privs() || run_anyway) { +#if 0 + /* wslua_dofile / wslua_get_actual_filename look in the personal configuration + * directory. Should we add that to the path for require() as well, for consistency? + */ + profile_dir = get_profile_dir(NULL, false); + prepend_path(profile_dir); + g_free(profile_dir); +#endif + /* Add the personal plugins path(s) for require() */ + char *old_path = get_persconffile_path("plugins", false); + if (strcmp(get_plugins_pers_dir(), old_path) != 0) { + prepend_path(old_path); + } + g_free(old_path); + prepend_path(get_plugins_pers_dir()); filename = g_build_filename(get_plugins_pers_dir(), "init.lua", (char *)NULL); if (file_exists(filename)) { ws_debug("Loading init.lua file: %s", filename); @@ -1621,7 +1716,7 @@ void wslua_init(register_cb cb, gpointer client_data) { g_free(filename); /* For backward compatibility also load it from the configuration directory. */ - filename = get_persconffile_path("init.lua", FALSE); + filename = get_persconffile_path("init.lua", false); if (file_exists(filename)) { ws_message("Loading init.lua file from deprecated path: %s", filename); lua_load_internal_script(filename); @@ -1648,18 +1743,18 @@ void wslua_init(register_cb cb, gpointer client_data) { /* disable lua */ lua_close(L); L = NULL; - first_time = FALSE; + first_time = false; return; } /* load global scripts */ - lua_load_global_plugins(cb, client_data, FALSE); + lua_load_global_plugins(cb, client_data, false); /* check whether we should run other scripts even if running superuser */ lua_getglobal(L,"run_user_scripts_when_superuser"); if (lua_isboolean(L,-1) && lua_toboolean(L,-1)) { - run_anyway = TRUE; + run_anyway = true; } lua_pop(L,1); /* pop the getglobal result */ @@ -1667,13 +1762,19 @@ void wslua_init(register_cb cb, gpointer client_data) { if (!started_with_special_privs() || run_anyway) { /* load user scripts */ - lua_load_pers_plugins(cb, client_data, FALSE); + lua_load_pers_plugins(cb, client_data, false); /* load scripts from command line */ for (i = 0; i < ex_opt_count("lua_script"); i++) { - const gchar *script_filename = ex_opt_get_nth("lua_script", i); + const char *script_filename = ex_opt_get_nth("lua_script", i); char* dirname = g_strdup(script_filename); char* dname = get_dirname(dirname); + /* Add the command line script directory to the path (unless it's + * the current directory, which should already be in the path by + * default). + * XXX - Should we remove it after we're done with this script? */ + if (dname) + prepend_path(dname); if (cb) (*cb)(RA_LUA_PLUGINS, get_basename(script_filename), client_data); @@ -1728,14 +1829,14 @@ void wslua_init(register_cb cb, gpointer client_data) { } } - first_time = FALSE; + first_time = false; } void wslua_early_cleanup(void) { wslua_deregister_protocols(L); } -void wslua_reload_plugins (register_cb cb, gpointer client_data) { +void wslua_reload_plugins (register_cb cb, void *client_data) { const funnel_ops_t* ops = funnel_get_funnel_ops(); if (cb) @@ -1763,7 +1864,7 @@ void wslua_cleanup(void) { lua_close(L); L = NULL; } - init_routine_initialized = FALSE; + init_routine_initialized = false; } lua_State* wslua_state(void) { return L; } diff --git a/epan/wslua/init_wslua.h b/epan/wslua/init_wslua.h index 5063076d..681dcacc 100644 --- a/epan/wslua/init_wslua.h +++ b/epan/wslua/init_wslua.h @@ -17,7 +17,7 @@ extern "C" { #endif /* __cplusplus */ WS_DLL_PUBLIC int wslua_count_plugins(void); -WS_DLL_PUBLIC void wslua_reload_plugins (register_cb cb, gpointer client_data); +WS_DLL_PUBLIC void wslua_reload_plugins (register_cb cb, void *client_data); typedef void (*wslua_plugin_description_callback)(const char *, const char *, const char *, const char *, diff --git a/epan/wslua/lrexlib/CMakeLists.txt b/epan/wslua/lrexlib/CMakeLists.txt index 2f7231ef..e87988bd 100644 --- a/epan/wslua/lrexlib/CMakeLists.txt +++ b/epan/wslua/lrexlib/CMakeLists.txt @@ -21,10 +21,10 @@ target_include_directories(lrexlib SYSTEM PRIVATE add_dependencies(lrexlib register_wslua) if(FETCH_lua) - add_dependencies(lrexlib lua52) + add_dependencies(lrexlib lua54) endif() add_compile_definitions( - VERSION=\"2.9.1\" + VERSION=\"2.9.2\" PCRE2_CODE_UNIT_WIDTH=8 ) diff --git a/epan/wslua/lrexlib/LICENSE b/epan/wslua/lrexlib/LICENSE new file mode 100644 index 00000000..cfd2df47 --- /dev/null +++ b/epan/wslua/lrexlib/LICENSE @@ -0,0 +1,27 @@ +License of Lrexlib release +-------------------------- + +Copyright (C) Reuben Thomas 2000-2020 +Copyright (C) Shmuel Zeigerman 2004-2020 + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall +be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/epan/wslua/lrexlib/README.rst b/epan/wslua/lrexlib/README.rst index b9679d35..660e8475 100644 --- a/epan/wslua/lrexlib/README.rst +++ b/epan/wslua/lrexlib/README.rst @@ -5,7 +5,7 @@ Lrexlib | and Shmuel Zeigerman (shmuz@013net.net) **Lrexlib** provides bindings of five regular expression library APIs -(POSIX_, PCRE_, PCRE2_, GNU_, TRE_ and Oniguruma_) to Lua_ >= 5.1. +(POSIX_, PCRE_, GNU_, TRE_ and Oniguruma_) to Lua_ >= 5.1. The bindings for TRE and Oniguruma are not currently complete. **Lrexlib** is copyright Reuben Thomas 2000-2020 and copyright Shmuel @@ -13,17 +13,17 @@ Zeigerman 2004-2020, and is released under the same license as Lua, the MIT_ license (otherwise known as the revised BSD license). There is no warranty. -.. _POSIX: http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html -.. _PCRE: http://www.pcre.org/pcre.txt -.. _PCRE2: http://www.pcre.org/pcre2.txt -.. _GNU: ftp://ftp.gnu.org/old-gnu/regex/ +.. _POSIX: https://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html +.. _PCRE: https://www.pcre.org/current/doc/html/ +.. _GNU: https://ftp.gnu.org/old-gnu/regex/ .. _Oniguruma: https://github.com/kkos/oniguruma -.. _TRE: http://laurikari.net/tre/documentation/ -.. _Lua: http://www.lua.org -.. _MIT: http://www.opensource.org/licenses/mit-license.php +.. _TRE: https://laurikari.net/tre/documentation/ +.. _Lua: https://www.lua.org +.. _MIT: https://www.opensource.org/licenses/mit-license.php -Please report bugs and make suggestions to the maintainer, or use the -LuaForge trackers and mailing lists. +Please report bugs and make suggestions on GitHub_. + +.. _GitHub: https://github.com/rrthomas/lrexlib/issues Thanks to Thatcher Ulrich for bug and warning fixes, and to Nick Gammon for adding support for PCRE named subpatterns. @@ -37,20 +37,22 @@ Lrexlib is installed with LuaRocks_, using the command:: luarocks install lrexlib-FLAVOUR -where **FLAVOUR** is one of PCRE, PCRE2, POSIX, oniguruma, TRE, GNU +where **FLAVOUR** is one of PCRE2, POSIX, oniguruma, TRE, GNU + +Note that the obsolete PCRE version 1 is also supported, as flavour PCRE. -.. _LuaRocks: http://www.luarocks.org +.. _LuaRocks: https://luarocks.org Links ----- +- `GitHub project page`_ - License_ - `Reference Manual`_ -- `LuaForge Project Page`_ -- Download_ +- Downloads_ -.. _License: http://rrthomas.github.com/lrexlib/license.html -.. _Reference Manual: http://rrthomas.github.com/lrexlib/manual.html -.. _LuaForge Project Page: http://luaforge.net/projects/lrexlib/ -.. _Download: https://github.com/rrthomas/lrexlib/downloads +.. _GitHub project page: https://github.com/rrthomas/lrexlib +.. _License: https://rrthomas.github.io/lrexlib/license.html +.. _Reference Manual: https://rrthomas.github.io/lrexlib/manual.html +.. _Downloads: https://github.com/rrthomas/lrexlib/downloads diff --git a/epan/wslua/lrexlib/algo.h b/epan/wslua/lrexlib/algo.h index 2e7a38ab..0d16d757 100644 --- a/epan/wslua/lrexlib/algo.h +++ b/epan/wslua/lrexlib/algo.h @@ -1,30 +1,6 @@ /* algo.h */ -/* - * Copyright (C) Reuben Thomas 2000-2020 - * Copyright (C) Shmuel Zeigerman 2004-2020 - - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - - * The above copyright notice and this permission notice shall - * be included in all copies or substantial portions of the - * Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY - * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS - * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +/* See Copyright Notice in the file LICENSE */ +/* SPDX-License-Identifier: MIT */ #include "common.h" diff --git a/epan/wslua/lrexlib/common.c b/epan/wslua/lrexlib/common.c index 4d42de9c..0c50ec94 100644 --- a/epan/wslua/lrexlib/common.c +++ b/epan/wslua/lrexlib/common.c @@ -1,30 +1,6 @@ /* common.c */ -/* - * Copyright (C) Reuben Thomas 2000-2020 - * Copyright (C) Shmuel Zeigerman 2004-2020 - - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - - * The above copyright notice and this permission notice shall - * be included in all copies or substantial portions of the - * Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY - * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS - * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +/* See Copyright Notice in the file LICENSE */ +/* SPDX-License-Identifier: MIT */ #include <wireshark.h> DIAG_OFF_CLANG(shorten-64-to-32) diff --git a/epan/wslua/lrexlib/common.h b/epan/wslua/lrexlib/common.h index 121e54c7..a93828f6 100644 --- a/epan/wslua/lrexlib/common.h +++ b/epan/wslua/lrexlib/common.h @@ -1,30 +1,6 @@ /* common.h */ -/* - * Copyright (C) Reuben Thomas 2000-2020 - * Copyright (C) Shmuel Zeigerman 2004-2020 - - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - - * The above copyright notice and this permission notice shall - * be included in all copies or substantial portions of the - * Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY - * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS - * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +/* See Copyright Notice in the file LICENSE */ +/* SPDX-License-Identifier: MIT */ #ifndef COMMON_H #define COMMON_H @@ -32,7 +8,9 @@ #include "lua.h" #if LUA_VERSION_NUM > 501 -# define lua_objlen lua_rawlen +# ifndef lua_objlen +# define lua_objlen lua_rawlen +# endif int luaL_typerror (lua_State *L, int narg, const char *tname); #endif diff --git a/epan/wslua/lrexlib/pcre2/lpcre2.c b/epan/wslua/lrexlib/pcre2/lpcre2.c index f24cbec8..f278bbab 100644 --- a/epan/wslua/lrexlib/pcre2/lpcre2.c +++ b/epan/wslua/lrexlib/pcre2/lpcre2.c @@ -1,30 +1,6 @@ /* lpcre2.c - Lua binding of PCRE2 library */ -/* - * Copyright (C) Reuben Thomas 2000-2020 - * Copyright (C) Shmuel Zeigerman 2004-2020 - - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - - * The above copyright notice and this permission notice shall - * be included in all copies or substantial portions of the - * Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY - * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS - * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +/* See Copyright Notice in the file LICENSE */ +/* SPDX-License-Identifier: MIT */ #include <wireshark.h> DIAG_OFF_CLANG(shorten-64-to-32) @@ -432,7 +408,7 @@ static int Lpcre2_jit_compile (lua_State *L) { #define SET_INFO_FIELD(L,ud,what,name,valtype) { \ valtype val; \ if (0 == pcre2_pattern_info (ud->pr, what, &val)) { \ - lua_pushnumber (L, val); \ + lua_pushinteger (L, val); \ lua_setfield (L, -2, name); \ } \ } diff --git a/epan/wslua/lrexlib/pcre2/lpcre2_f.c b/epan/wslua/lrexlib/pcre2/lpcre2_f.c index 659c8ac7..e79d850d 100644 --- a/epan/wslua/lrexlib/pcre2/lpcre2_f.c +++ b/epan/wslua/lrexlib/pcre2/lpcre2_f.c @@ -1,30 +1,6 @@ /* lpcre2_f.c - Lua binding of PCRE2 library */ -/* - * Copyright (C) Reuben Thomas 2000-2020 - * Copyright (C) Shmuel Zeigerman 2004-2020 - - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - - * The above copyright notice and this permission notice shall - * be included in all copies or substantial portions of the - * Software. - - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY - * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS - * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +/* See Copyright Notice in the file LICENSE */ +/* SPDX-License-Identifier: MIT */ #include <pcre2.h> #include "lua.h" diff --git a/epan/wslua/lua_bitop.c b/epan/wslua/lua_bitop.c index 52be189a..10bfb9bf 100644 --- a/epan/wslua/lua_bitop.c +++ b/epan/wslua/lua_bitop.c @@ -36,11 +36,7 @@ static UBits barg(lua_State *L, int idx) { BitNum bn; UBits b; -#if LUA_VERSION_NUM < 502 - bn.n = lua_tonumber(L, idx); -#else bn.n = luaL_checknumber(L, idx); -#endif #if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE) bn.n += 6755399441055744.0; /* 2^52+2^51 */ #ifdef SWAPPED_DOUBLE @@ -61,11 +57,6 @@ static UBits barg(lua_State *L, int idx) #else #error "Unknown number type, check LUA_NUMBER_*, LUA_FLOAT_*, LUA_INT_* in luaconf.h" #endif -#if LUA_VERSION_NUM < 502 - if (b == 0 && !lua_isnumber(L, idx)) { - luaL_typerror(L, idx, "number"); - } -#endif return b; } @@ -168,13 +159,9 @@ DIAG_OFF(unreachable-code) DIAG_ON(unreachable-code) luaL_error(L, "bit library self-test failed (%s)", msg); } -#if LUA_VERSION_NUM < 502 - luaL_register(L, "bit", bit_funcs); - return 1; -#else + luaL_newlib(L, bit_funcs); lua_setglobal(L, "bit"); /* added for wireshark */ return 0; /* changed from 1 to 0 for wireshark, since lua_setglobal now pops the table */ -#endif } diff --git a/epan/wslua/make-taps.py b/epan/wslua/make-taps.py index 14c5a397..1cc3cfc4 100755 --- a/epan/wslua/make-taps.py +++ b/epan/wslua/make-taps.py @@ -34,18 +34,28 @@ def get_tap_info(tap_name, header_file, struct_name, enum_types): types = { 'gchar[]': 'lua_pushstring(L,(const char*)v->STR);', 'gchar*': 'lua_pushstring(L,(const char*)v->STR);', - 'guint': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'guint8': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'guint16': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'guint32': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'gint': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'gint8': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'gint16': 'lua_pushnumber(L,(lua_Number)v->STR);', - 'gint32': 'lua_pushnumber(L,(lua_Number)v->STR);', + 'guint': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'guint8': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'guint16': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'guint32': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'gint': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'gint8': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'gint16': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'gint32': 'lua_pushinteger(L,(lua_Integer)v->STR);', 'gboolean': 'lua_pushboolean(L,(int)v->STR);', + 'char[]': 'lua_pushstring(L,(const char*)v->STR);', + 'char*': 'lua_pushstring(L,(const char*)v->STR);', + 'unsigned': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'uint8_t': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'uint16_t': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'uint32_t': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'int': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'int8_t': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'int16_t': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'int32': 'lua_pushinteger(L,(lua_Integer)v->STR);', + 'bool': 'lua_pushboolean(L,(int)v->STR);', 'address': '{ Address a = (Address)g_malloc(sizeof(address)); copy_address(a, &(v->STR)); pushAddress(L,a); }', 'address*': '{ Address a = (Address)g_malloc(sizeof(address)); copy_address(a, v->STR); pushAddress(L,a); }', - 'int': 'lua_pushnumber(L,(lua_Number)v->STR);', 'nstime_t': 'lua_pushnumber(L,(lua_Number)nstime_to_sec(&(v->STR)));', 'nstime_t*': 'lua_pushnumber(L,(lua_Number)nstime_to_sec(v->STR));', } @@ -62,9 +72,19 @@ def get_tap_info(tap_name, header_file, struct_name, enum_types): 'gint16': 'number', 'gint32': 'number', 'gboolean': 'boolean', + 'char[]': 'string', + 'char*': 'string', + 'unsigned': 'number', + 'uint8_t': 'number', + 'uint16_t': 'number', + 'uint32_t': 'number', + 'int': 'number', + 'int8_t': 'number', + 'int16_t': 'number', + 'int32_t': 'number', + 'bool': 'boolean', 'address': 'Address', 'address*': 'Address', - 'int': 'number', 'nstime_t': 'number (seconds, since 1-1-1970 if absolute)', 'nstime_t*': 'number (seconds, since 1-1-1970 if absolute)', } @@ -79,7 +99,7 @@ def get_tap_info(tap_name, header_file, struct_name, enum_types): for enum in enum_types: m = re.search(fr'typedef\s+enum[^{{]*{{([^}}]*)}}[\s\n]*{enum}[\s\n]*;', buf, flags=re.DOTALL) if m: - types[enum] = f'lua_pushnumber(L,(lua_Number)v->STR); /* {enum} */' + types[enum] = f'lua_pushinteger(L,(lua_Integer)v->STR); /* {enum} */' econsts = m.group(1).splitlines() econsts = [re.sub(r'\s+', '', item) for item in econsts] econsts = [re.sub(',', '', item) for item in econsts] @@ -183,9 +203,9 @@ def main(): c_body += f'\n\t/*\n\t * {enum}\n\t */\n\tlua_newtable(L);\n' for econst in enums[enum]: c_body += f'''\ - lua_pushnumber(L,(lua_Number){econst}); + lua_pushinteger(L,(lua_Integer){econst}); lua_setglobal(L,"{econst}"); - lua_pushnumber(L,(lua_Number){econst}); + lua_pushinteger(L,(lua_Integer){econst}); lua_pushstring(L,"{econst}"); lua_settable(L,-3); ''' diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index c96f4f2c..00c8feea 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -58,39 +58,74 @@ #define WSLUA_PREFS_CHANGED "prefs_changed" /* type conversion macros - lua_Number is a double, so casting isn't kosher; and - using Lua's already-available lua_tointeger() and luaL_checkinteger() might be different - on different machines; so use these instead please! */ -#define wslua_togint(L,i) (gint) ( lua_tointeger(L,i) ) -#define wslua_togint32(L,i) (gint32) ( lua_tonumber(L,i) ) -#define wslua_togint64(L,i) (gint64) ( lua_tonumber(L,i) ) -#define wslua_toguint(L,i) (guint) ( lua_tointeger(L,i) ) -#define wslua_toguint32(L,i) (guint32) ( lua_tonumber(L,i) ) -#define wslua_toguint64(L,i) (guint64) ( lua_tonumber(L,i) ) - -#define wslua_checkgint(L,i) (gint) ( luaL_checkinteger(L,i) ) -#define wslua_checkgint32(L,i) (gint32) ( luaL_checknumber(L,i) ) -#define wslua_checkgint64(L,i) (gint64) ( luaL_checknumber(L,i) ) -#define wslua_checkguint(L,i) (guint) ( luaL_checkinteger(L,i) ) -#define wslua_checkguint32(L,i) (guint32) ( luaL_checknumber(L,i) ) -#define wslua_checkguint64(L,i) (guint64) ( luaL_checknumber(L,i) ) - -#define wslua_optgint(L,i,d) (gint) ( luaL_optinteger(L,i,d) ) -#define wslua_optgint32(L,i,d) (gint32) ( luaL_optnumber(L,i,d) ) -#define wslua_optgint64(L,i,d) (gint64) ( luaL_optnumber(L,i,d) ) -#define wslua_optguint(L,i,d) (guint) ( luaL_optinteger(L,i,d) ) -#define wslua_optguint32(L,i,d) (guint32) ( luaL_optnumber(L,i,d) ) -#define wslua_optguint64(L,i,d) (guint64) ( luaL_optnumber(L,i,d) ) + using Lua's already-available lua_tointeger() and luaL_checkinteger() might be + different on different machines; so use these instead please! + + It can be important to choose the correct version of signed or unsigned + conversion macros; don't assume that you can freely convert to the signed + or unsigned integer of the same size later: + + On 32-bit Windows x86, Lua 5.2 and earlier must use lua_tounsigned() and + luaL_checkunsigned() due to the use of float to integer inlined assembly. + (#18367) + On ARM, casting from a negative floating point number to an unsigned integer + type doesn't perform wraparound conversion in the same way as casting from + float to the same size signed integer then to unsigned does, unlike x86[-64]. + (Commit 15392c324d5eaefcaa298cdee09cd5b40b12e09c) + + On Lua 5.3 and later, numbers are stored as a kind of union between + Lua_Number and Lua_Integer. On 5.2 and earlier. all numbers are stored + as Lua_Number internally. + + Be careful about using the 64-bit functions, as they convert from double + and lose precision at high values. See wslua_int64.c and the types there. + TODO: Check if Lua_Integer is 64 bit on Lua 5.3 and later. +*/ +#define wslua_toint(L,i) (int) ( lua_tointeger(L,i) ) +#define wslua_toint32(L,i) (int32_t) ( lua_tointeger(L,i) ) +#define wslua_toint64(L,i) (int64_t) ( lua_tonumber(L,i) ) +#define wslua_touint64(L,i) (uint64_t) ( lua_tonumber(L,i) ) + +#define wslua_checkint(L,i) (int) ( luaL_checkinteger(L,i) ) +#define wslua_checkint32(L,i) (int32_t) ( luaL_checkinteger(L,i) ) +#define wslua_checkint64(L,i) (int64_t) ( luaL_checknumber(L,i) ) +#define wslua_checkuint64(L,i) (uint64_t) ( luaL_checknumber(L,i) ) + +#define wslua_optint(L,i,d) (int) ( luaL_optinteger(L,i,d) ) +#define wslua_optint32(L,i,d) (int32_t) ( luaL_optinteger(L,i,d) ) +#define wslua_optint64(L,i,d) (int64_t) ( luaL_optnumber(L,i,d) ) +#define wslua_optuint64(L,i,d) (uint64_t) ( luaL_optnumber(L,i,d) ) +/** + * On Lua 5.3 and later, the unsigned conversions may not be defined + * (depending on a compatibility define), and they're just casts if they + * are. + */ +#if LUA_VERSION_NUM < 503 +#define wslua_touint(L,i) (unsigned) ( lua_tounsigned(L,i) ) +#define wslua_touint32(L,i) (uint32_t) ( lua_tounsigned(L,i) ) +#define wslua_checkuint(L,i) (unsigned) ( luaL_checkunsigned(L,i) ) +#define wslua_checkuint32(L,i) (uint32_t) ( luaL_checkunsigned(L,i) ) +#define wslua_optuint(L,i,d) (unsigned) ( luaL_optunsigned(L,i,d) ) +#define wslua_optuint32(L,i,d) (uint32_t) ( luaL_optunsigned(L,i,d) ) +#else +#define wslua_touint(L,i) (unsigned) ( lua_tointeger(L,i) ) +#define wslua_touint32(L,i) (uint32_t) ( lua_tointeger(L,i) ) +#define wslua_checkuint(L,i) (unsigned) ( luaL_checkinteger(L,i) ) +#define wslua_checkuint32(L,i) (uint32_t) ( luaL_checkinteger(L,i) ) +#define wslua_optuint(L,i,d) (unsigned) ( luaL_optinteger(L,i,d) ) +#define wslua_optuint32(L,i,d) (uint32_t) ( luaL_optinteger(L,i,d) ) +#endif struct _wslua_tvb { tvbuff_t* ws_tvb; - gboolean expired; - gboolean need_free; + bool expired; + bool need_free; }; struct _wslua_pinfo { packet_info* ws_pinfo; - gboolean expired; + bool expired; }; struct _wslua_tvbrange { @@ -101,7 +136,7 @@ struct _wslua_tvbrange { struct _wslua_tw { funnel_text_window_t* ws_tw; - gboolean expired; + bool expired; void* close_cb_data; }; @@ -114,13 +149,14 @@ typedef struct _wslua_field_t { enum ftenum type; unsigned base; const void* vs; - guint64 mask; + int valuestring_ref; + uint64_t mask; } wslua_field_t; typedef struct _wslua_expert_field_t { expert_field ids; - const gchar *abbrev; - const gchar *text; + const char *abbrev; + const char *text; int group; int severity; } wslua_expert_field_t; @@ -140,28 +176,28 @@ typedef enum { } pref_type_t; typedef struct _wslua_pref_t { - gchar* name; - gchar* label; - gchar* desc; + char* name; + char* label; + char* desc; pref_type_t type; union { - gboolean b; - guint u; - gchar* s; - gint e; + bool b; + unsigned u; + char* s; + int e; range_t *r; void* p; } value; union { - guint32 max_value; /**< maximum value of a range */ + uint32_t max_value; /**< maximum value of a range */ struct { const enum_val_t *enumvals; /**< list of name & values */ - gboolean radio_buttons; /**< TRUE if it should be shown as + bool radio_buttons; /**< true if it should be shown as radio buttons rather than as an option menu or combo box in the preferences tab */ } enum_info; /**< for PREF_ENUM */ - gchar* default_s; /**< default value for value.s */ + char* default_s; /**< default value for value.s */ } info; /**< display/text file information */ struct _wslua_pref_t* next; @@ -170,9 +206,9 @@ typedef struct _wslua_pref_t { } wslua_pref_t; typedef struct _wslua_proto_t { - gchar* name; - gchar* loname; - gchar* desc; + char* name; + char* loname; + char* desc; int hfid; int ett; wslua_pref_t prefs; @@ -184,8 +220,8 @@ typedef struct _wslua_proto_t { GArray *hfa; GArray *etta; GArray *eia; - gboolean is_postdissector; - gboolean expired; + bool is_postdissector; + bool expired; } wslua_proto_t; /* a "DissectorTable" object can be different things under the hood, @@ -194,33 +230,33 @@ typedef struct _wslua_proto_t { struct _wslua_distbl_t { dissector_table_t table; heur_dissector_list_t heur_list; - const gchar* name; - const gchar* ui_name; - gboolean created; - gboolean expired; + const char* name; + const char* ui_name; + bool created; + bool expired; }; struct _wslua_col_info { column_info* cinfo; - gint col; - gboolean expired; + int col; + bool expired; }; struct _wslua_cols { column_info* cinfo; - gboolean expired; + bool expired; }; struct _wslua_private_table { GHashTable *table; - gboolean is_allocated; - gboolean expired; + bool is_allocated; + bool expired; }; struct _wslua_treeitem { proto_item* item; proto_tree* tree; - gboolean expired; + bool expired; }; // Internal structure for wslua_field.c to track info about registered fields. @@ -231,20 +267,20 @@ struct _wslua_header_field_info { struct _wslua_field_info { field_info *ws_fi; - gboolean expired; + bool expired; }; typedef void (*tap_extractor_t)(lua_State*,const void*); struct _wslua_tap { - gchar* name; - gchar* filter; + char* name; + char* filter; tap_extractor_t extractor; lua_State* L; int packet_ref; int draw_ref; int reset_ref; - gboolean all_fields; + bool all_fields; }; /* a "File" object can be different things under the hood. It can either @@ -255,35 +291,35 @@ struct _wslua_tap { struct _wslua_file { FILE_T file; wtap_dumper *wdh; /* will be NULL during read usage */ - gboolean expired; + bool expired; }; /* a "CaptureInfo" object can also be different things under the hood. */ struct _wslua_captureinfo { wtap *wth; /* will be NULL during write usage */ wtap_dumper *wdh; /* will be NULL during read usage */ - gboolean expired; + bool expired; }; struct _wslua_phdr { wtap_rec *rec; /* this also exists in wtap struct, but is different for seek_read ops */ Buffer *buf; /* can't use the one in wtap because it's different for seek_read ops */ - gboolean expired; + bool expired; }; struct _wslua_const_phdr { const wtap_rec *rec; - const guint8 *pd; - gboolean expired; + const uint8_t *pd; + bool expired; }; struct _wslua_filehandler { struct file_type_subtype_info finfo; - gboolean is_reader; - gboolean is_writer; - gchar* internal_description; /* XXX - this is redundant; finfo.description should suffice */ - gchar* type; - gchar* extensions; + bool is_reader; + bool is_writer; + char* internal_description; /* XXX - this is redundant; finfo.description should suffice */ + char* type; + char* extensions; lua_State* L; int read_open_ref; int read_ref; @@ -295,8 +331,8 @@ struct _wslua_filehandler { int write_ref; int write_close_ref; int file_type; - gboolean registered; - gboolean removed; /* This is set during reload Lua plugins */ + bool registered; + bool removed; /* This is set during reload Lua plugins */ }; struct _wslua_dir { @@ -308,12 +344,12 @@ struct _wslua_progdlg { struct progdlg* pw; char* title; char* task; - gboolean stopped; + bool stopped; }; typedef struct { const char* name; tap_extractor_t extractor; } tappable_t; -typedef struct {const gchar* str; enum ftenum id; } wslua_ft_types_t; +typedef struct {const char* str; enum ftenum id; } wslua_ft_types_t; typedef wslua_pref_t* Pref; typedef wslua_pref_t* Prefs; @@ -331,8 +367,8 @@ typedef struct _wslua_pinfo* Pinfo; typedef struct _wslua_treeitem* TreeItem; typedef address* Address; typedef nstime_t* NSTime; -typedef gint64 Int64; -typedef guint64 UInt64; +typedef int64_t Int64; +typedef uint64_t UInt64; typedef struct _wslua_header_field_info* Field; typedef struct _wslua_field_info* FieldInfo; typedef struct _wslua_tap* Listener; @@ -352,7 +388,7 @@ typedef tvbparse_elem_t* Node; typedef tvbparse_action_t* Shortcut; typedef struct _wslua_dir* Dir; typedef struct _wslua_private_table* PrivateTable; -typedef gchar* Struct; +typedef char* Struct; /* * toXxx(L,idx) gets a Xxx from an index (Lua Error if fails) @@ -386,14 +422,14 @@ C* push##C(lua_State* L, C v) { \ luaL_getmetatable(L, #C); lua_setmetatable(L, -2); \ return p; \ }\ -gboolean is##C(lua_State* L,int i) { \ +bool is##C(lua_State* L,int i) { \ void *p; \ - if(!lua_isuserdata(L,i)) return FALSE; \ + if(!lua_isuserdata(L,i)) return false; \ p = lua_touserdata(L, i); \ lua_getfield(L, LUA_REGISTRYINDEX, #C); \ if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \ lua_pop(L, 2); \ - return p ? TRUE : FALSE; \ + return p ? true : false; \ } \ C shift##C(lua_State* L,int i) { \ C* p; \ @@ -408,11 +444,11 @@ C shift##C(lua_State* L,int i) { \ typedef int dummy##C typedef struct _wslua_attribute_table { - const gchar *fieldname; + const char *fieldname; lua_CFunction getfunc; lua_CFunction setfunc; } wslua_attribute_table; -extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gboolean is_getter); +extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, bool is_getter); #define WSLUA_TYPEOF_FIELD "__typeof" @@ -518,11 +554,11 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb #define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(C,name,member) \ WSLUA_ATTRIBUTE_GET(C,name,{lua_pushboolean(L, obj->member );}) -#define WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(C,name,member) \ - WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(obj->member));}) +#define WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,name,member) \ + WSLUA_ATTRIBUTE_GET(C,name,{lua_pushinteger(L,(lua_Integer)(obj->member));}) -#define WSLUA_ATTRIBUTE_NUMBER_GETTER(C,member) \ - WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(C,member,member) +#define WSLUA_ATTRIBUTE_INTEGER_GETTER(C,member) \ + WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,member,member) #define WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(C,name,block) \ WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(block));}) @@ -577,20 +613,20 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb /* to make this integral-safe, we treat it as int32 and then cast Note: This will truncate 64-bit integers (but then Lua itself only has doubles */ -#define WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(C,name,member,cast) \ +#define WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,name,member,cast) \ WSLUA_ATTRIBUTE_SET(C,name, { \ - if (! lua_isnumber(L,-1) ) \ - return luaL_error(L, "%s's attribute `%s' must be a number", #C , #name ); \ - obj->member = (cast) wslua_togint32(L,-1); \ + if (! lua_isinteger(L,-1) ) \ + return luaL_error(L, "%s's attribute `%s' must be an integer", #C , #name ); \ + obj->member = (cast) wslua_toint32(L,-1); \ }) -#define WSLUA_ATTRIBUTE_NUMBER_SETTER(C,member,cast) \ - WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(C,member,member,cast) +#define WSLUA_ATTRIBUTE_INTEGER_SETTER(C,member,cast) \ + WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,member,member,cast) #define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,member,need_free) \ static int C##_set_##field (lua_State* L) { \ C obj = check##C (L,1); \ - gchar* s = NULL; \ + char* s = NULL; \ if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \ s = g_strdup(lua_tostring(L,-1)); \ } else { \ @@ -610,7 +646,7 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb #define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(C,field,member,option) \ static int C##_set_##field (lua_State* L) { \ C obj = check##C (L,1); \ - gchar* s = NULL; \ + char* s = NULL; \ if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \ s = g_strdup(lua_tostring(L,-1)); \ } else { \ @@ -628,7 +664,7 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb #define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(C,field,member,option) \ static int C##_set_##field (lua_State* L) { \ C obj = check##C (L,1); \ - gchar* s = NULL; \ + char* s = NULL; \ if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \ s = g_strdup(lua_tostring(L,-1)); \ } else { \ @@ -649,7 +685,7 @@ extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gb #define WSLUA_REG_GLOBAL_BOOL(L,n,v) { lua_pushboolean(L,v); lua_setglobal(L,n); } #define WSLUA_REG_GLOBAL_STRING(L,n,v) { lua_pushstring(L,v); lua_setglobal(L,n); } -#define WSLUA_REG_GLOBAL_NUMBER(L,n,v) { lua_pushnumber(L,v); lua_setglobal(L,n); } +#define WSLUA_REG_GLOBAL_INTEGER(L,n,v) { lua_pushinteger(L,v); lua_setglobal(L,n); } #define WSLUA_RETURN(i) return (i) @@ -684,7 +720,7 @@ extern C to##C(lua_State* L, int idx); \ extern C check##C(lua_State* L, int idx); \ extern C* push##C(lua_State* L, C v); \ extern int C##_register(lua_State* L); \ -extern gboolean is##C(lua_State* L,int i); \ +extern bool is##C(lua_State* L,int i); \ extern C shift##C(lua_State* L,int i) @@ -696,12 +732,12 @@ extern C shift##C(lua_State* L,int i) * Normal restrictions for TRY/CATCH apply, in particular, do not return! */ #define WRAP_NON_LUA_EXCEPTIONS(code) \ { \ - volatile gboolean has_error = FALSE; \ + volatile bool has_error = false; \ TRY { \ code \ } CATCH_ALL { \ lua_pushstring(L, GET_MESSAGE); \ - has_error = TRUE; \ + has_error = true; \ } ENDTRY; \ if (has_error) { lua_error(L); } \ } @@ -710,7 +746,7 @@ extern C shift##C(lua_State* L,int i) extern packet_info* lua_pinfo; extern TreeItem lua_tree; extern tvbuff_t* lua_tvb; -extern gboolean lua_initialized; +extern bool lua_initialized; extern int lua_dissectors_table_ref; extern int lua_heur_dissectors_table_ref; @@ -739,26 +775,26 @@ void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def) void wslua_register_class(lua_State *L, const wslua_class *cls_def); extern int wslua__concat(lua_State* L); -extern gboolean wslua_toboolean(lua_State* L, int n); -extern gboolean wslua_checkboolean(lua_State* L, int n); -extern gboolean wslua_optbool(lua_State* L, int n, gboolean def); +extern bool wslua_toboolean(lua_State* L, int n); +extern bool wslua_checkboolean(lua_State* L, int n); +extern bool wslua_optbool(lua_State* L, int n, bool def); extern lua_Integer wslua_tointeger(lua_State* L, int n); extern int wslua_optboolint(lua_State* L, int n, int def); extern const char* wslua_checklstring_only(lua_State* L, int n, size_t *l); extern const char* wslua_checkstring_only(lua_State* L, int n); extern void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup); -extern const gchar* wslua_typeof_unknown; -extern const gchar* wslua_typeof(lua_State *L, int idx); -extern gboolean wslua_get_table(lua_State *L, int idx, const gchar *name); -extern gboolean wslua_get_field(lua_State *L, int idx, const gchar *name); +extern const char* wslua_typeof_unknown; +extern const char* wslua_typeof(lua_State *L, int idx); +extern bool wslua_get_table(lua_State *L, int idx, const char *name); +extern bool wslua_get_field(lua_State *L, int idx, const char *name); extern int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data); -extern int heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data); +extern bool heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data); extern expert_field* wslua_get_expert_field(const int group, const int severity); extern void wslua_prefs_changed(void); extern void proto_register_lua(void); extern GString* lua_register_all_taps(void); extern void wslua_prime_dfilter(epan_dissect_t *edt); -extern gboolean wslua_has_field_extractors(void); +extern bool wslua_has_field_extractors(void); extern void lua_prime_all_fields(proto_tree* tree); extern int Proto_commit(lua_State* L); @@ -767,15 +803,15 @@ extern TreeItem create_TreeItem(proto_tree* tree, proto_item* item); extern void clear_outstanding_FuncSavers(void); -extern void Int64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian); -extern int Int64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian); -extern void UInt64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian); -extern int UInt64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian); -extern guint64 getUInt64(lua_State *L, int i); +extern void Int64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian); +extern int Int64_unpack(lua_State* L, const char *buff, bool asLittleEndian); +extern void UInt64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian); +extern int UInt64_unpack(lua_State* L, const char *buff, bool asLittleEndian); +extern uint64_t getUInt64(lua_State *L, int i); extern Tvb* push_Tvb(lua_State* L, tvbuff_t* tvb); extern int push_wsluaTvb(lua_State* L, Tvb t); -extern gboolean push_TvbRange(lua_State* L, tvbuff_t* tvb, int offset, int len); +extern bool push_TvbRange(lua_State* L, tvbuff_t* tvb, int offset, int len); extern void clear_outstanding_Tvb(void); extern void clear_outstanding_TvbRange(void); @@ -794,22 +830,22 @@ extern void clear_outstanding_FieldInfo(void); extern void wslua_print_stack(char* s, lua_State* L); -extern void wslua_init(register_cb cb, gpointer client_data); +extern void wslua_init(register_cb cb, void *client_data); extern void wslua_early_cleanup(void); extern void wslua_cleanup(void); -extern tap_extractor_t wslua_get_tap_extractor(const gchar* name); +extern tap_extractor_t wslua_get_tap_extractor(const char* name); extern int wslua_set_tap_enums(lua_State* L); extern ProtoField wslua_is_field_available(lua_State* L, const char* field_abbr); extern char* wslua_get_actual_filename(const char* fname); -extern int wslua_bin2hex(lua_State* L, const guint8* data, const guint len, const gboolean lowercase, const gchar* sep); -extern int wslua_hex2bin(lua_State* L, const char* data, const guint len, const gchar* sep); +extern int wslua_bin2hex(lua_State* L, const uint8_t* data, const unsigned len, const bool lowercase, const char* sep); +extern int wslua_hex2bin(lua_State* L, const char* data, const unsigned len, const char* sep); extern int luaopen_rex_pcre2(lua_State *L); -extern const gchar* get_current_plugin_version(void); +extern const char* get_current_plugin_version(void); extern void clear_current_plugin_version(void); extern int wslua_deregister_heur_dissectors(lua_State* L); diff --git a/epan/wslua/wslua_address.c b/epan/wslua/wslua_address.c index ea89af3a..7bba1863 100644 --- a/epan/wslua/wslua_address.c +++ b/epan/wslua/wslua_address.c @@ -31,8 +31,8 @@ WSLUA_CONSTRUCTOR Address_ip(lua_State* L) { #define WSLUA_ARG_Address_ip_HOSTNAME 1 /* The address or name of the IP host. */ Address addr = (Address)g_malloc(sizeof(address)); - guint32 ip_addr; - const gchar* name = luaL_checkstring(L,WSLUA_ARG_Address_ip_HOSTNAME); + uint32_t ip_addr; + const char* name = luaL_checkstring(L,WSLUA_ARG_Address_ip_HOSTNAME); if (! get_host_ipaddr(name, &ip_addr)) { ip_addr = 0; @@ -49,7 +49,7 @@ WSLUA_CONSTRUCTOR Address_ipv6(lua_State* L) { #define WSLUA_ARG_Address_ipv6_HOSTNAME 1 /* The address or name of the IP host. */ Address addr = (Address)g_malloc(sizeof(address)); ws_in6_addr ip_addr; - const gchar* name = luaL_checkstring(L,WSLUA_ARG_Address_ipv6_HOSTNAME); + const char* name = luaL_checkstring(L,WSLUA_ARG_Address_ipv6_HOSTNAME); if (!get_host_ipaddr6(name, &ip_addr)) { memset(&ip_addr, 0, sizeof(ip_addr)); @@ -65,8 +65,8 @@ WSLUA_CONSTRUCTOR Address_ether(lua_State *L) { #define WSLUA_ARG_Address_ether_ETH 1 /* The Ethernet address. */ Address addr = (Address)g_malloc(sizeof(address)); - const gchar *name = luaL_checkstring(L, WSLUA_ARG_Address_ether_ETH); - guint8 eth_buf[6]; + const char *name = luaL_checkstring(L, WSLUA_ARG_Address_ether_ETH); + uint8_t eth_buf[6]; if(!str_to_eth(name, eth_buf)) memset(eth_buf, 0, sizeof(eth_buf)); @@ -191,7 +191,7 @@ WSLUA_METHODS Address_methods[] = { WSLUA_METAMETHOD Address__tostring(lua_State* L) { Address addr = checkAddress(L,1); - gchar *str = address_to_display(NULL, addr); + char *str = address_to_display(NULL, addr); lua_pushstring(L, str); @@ -215,10 +215,10 @@ static int Address__gc(lua_State* L) { WSLUA_METAMETHOD Address__eq(lua_State* L) { /* Compares two Addresses. */ Address addr1 = checkAddress(L,1); Address addr2 = checkAddress(L,2); - gboolean result = FALSE; + bool result = false; if (addresses_equal(addr1, addr2)) - result = TRUE; + result = true; lua_pushboolean(L,result); @@ -228,10 +228,10 @@ WSLUA_METAMETHOD Address__eq(lua_State* L) { /* Compares two Addresses. */ WSLUA_METAMETHOD Address__le(lua_State* L) { /* Compares two Addresses. */ Address addr1 = checkAddress(L,1); Address addr2 = checkAddress(L,2); - gboolean result = FALSE; + bool result = false; if (cmp_address(addr1, addr2) <= 0) - result = TRUE; + result = true; lua_pushboolean(L,result); @@ -241,10 +241,10 @@ WSLUA_METAMETHOD Address__le(lua_State* L) { /* Compares two Addresses. */ WSLUA_METAMETHOD Address__lt(lua_State* L) { /* Compares two Addresses. */ Address addr1 = checkAddress(L,1); Address addr2 = checkAddress(L,2); - gboolean result = FALSE; + bool result = false; if (cmp_address(addr1, addr2) < 0) - result = TRUE; + result = true; lua_pushboolean(L,result); diff --git a/epan/wslua/wslua_byte_array.c b/epan/wslua/wslua_byte_array.c index 6e6ae304..04155506 100644 --- a/epan/wslua/wslua_byte_array.c +++ b/epan/wslua/wslua_byte_array.c @@ -46,29 +46,29 @@ WSLUA_CONSTRUCTOR ByteArray_new(lua_State* L) { or if the boolean value `true` is used, then the first argument is treated as raw binary data */ GByteArray* ba = g_byte_array_new(); - const gchar* s; + const char* s; size_t len = 0; - const gchar* sep = " "; - gboolean ishex = TRUE; + const char* sep = " "; + bool ishex = true; if (lua_gettop(L) >= 1) { s = luaL_checklstring(L,WSLUA_OPTARG_ByteArray_new_HEXBYTES,&len); if (lua_gettop(L) >= 2) { if (lua_type(L,2) == LUA_TBOOLEAN && lua_toboolean(L,2)) { - ishex = FALSE; + ishex = false; } else { sep = luaL_optstring(L,WSLUA_OPTARG_ByteArray_new_SEPARATOR," "); } } if (ishex) { - wslua_hex2bin(L, s, (guint)len, sep); /* this pushes a new string on top of stack */ + wslua_hex2bin(L, s, (unsigned)len, sep); /* this pushes a new string on top of stack */ s = luaL_checklstring(L, -1, &len); /* get the new binary string */ - g_byte_array_append(ba,s,(guint)len); /* copy it into ByteArray */ + g_byte_array_append(ba,s,(unsigned)len); /* copy it into ByteArray */ lua_pop(L,1); /* pop the newly created string */ } else { - g_byte_array_append(ba,s,(guint)len); + g_byte_array_append(ba,s,(unsigned)len); } } @@ -83,7 +83,7 @@ static int ByteArray__gc(lua_State* L) { if (!ba) return 0; - g_byte_array_free(ba,TRUE); + g_byte_array_free(ba,true); return 0; } @@ -105,19 +105,16 @@ WSLUA_METAMETHOD ByteArray__concat(lua_State* L) { } WSLUA_METAMETHOD ByteArray__eq(lua_State* L) { - /* Compares two ByteArray values. - - @since 1.11.4 - */ + /* Compares two ByteArray values. */ #define WSLUA_ARG_ByteArray__eq_FIRST 1 /* First array. */ #define WSLUA_ARG_ByteArray__eq_SECOND 2 /* Second array. */ ByteArray ba1 = checkByteArray(L,WSLUA_ARG_ByteArray__eq_FIRST); ByteArray ba2 = checkByteArray(L,WSLUA_ARG_ByteArray__eq_SECOND); - gboolean result = FALSE; + bool result = false; if (ba1->len == ba2->len) { if (memcmp(ba1->data, ba2->data, ba1->len) == 0) - result = TRUE; + result = true; } lua_pushboolean(L,result); @@ -153,17 +150,17 @@ WSLUA_METHOD ByteArray_set_size(lua_State* L) { ByteArray ba = checkByteArray(L,1); int siz = (int)luaL_checkinteger(L,WSLUA_ARG_ByteArray_set_size_SIZE); - guint8* padding; + uint8_t* padding; if (siz < 0) { WSLUA_ERROR(ByteArray_set_size,"ByteArray size must be non-negative"); return 0; } - if (ba->len >= (guint)siz) { /* truncate */ + if (ba->len >= (unsigned)siz) { /* truncate */ g_byte_array_set_size(ba,siz); } else { /* fill */ - padding = (guint8 *)g_malloc0(sizeof(guint8)*(siz - ba->len)); + padding = (uint8_t *)g_malloc0(sizeof(uint8_t)*(siz - ba->len)); g_byte_array_append(ba,padding,siz - ba->len); g_free(padding); } @@ -183,7 +180,7 @@ WSLUA_METHOD ByteArray_set_index(lua_State* L) { return 0; } - if (idx < 0 || (guint)idx >= ba->len) { + if (idx < 0 || (unsigned)idx >= ba->len) { luaL_argerror(L,2,"index out of range"); return 0; } @@ -193,7 +190,7 @@ WSLUA_METHOD ByteArray_set_index(lua_State* L) { return 0; } - ba->data[idx] = (guint8)v; + ba->data[idx] = (uint8_t)v; return 0; } @@ -210,11 +207,11 @@ WSLUA_METHOD ByteArray_get_index(lua_State* L) { return 0; } - if (idx < 0 || (guint)idx >= ba->len) { + if (idx < 0 || (unsigned)idx >= ba->len) { luaL_argerror(L,2,"index out of range"); return 0; } - lua_pushnumber(L,ba->data[idx]); + lua_pushinteger(L,ba->data[idx]); WSLUA_RETURN(1); /* The value [0-255] of the byte. */ } @@ -222,7 +219,7 @@ WSLUA_METHOD ByteArray_get_index(lua_State* L) { WSLUA_METHOD ByteArray_le_int(lua_State* L) { /* Read a little endian encoded signed integer in a <<lua_class_ByteArray,`ByteArray`>> beginning at given offset with given length. - @since 4.1.0 + @since 4.2.0 */ #define WSLUA_OPTARG_ByteArray_le_int_OFFSET 2 /* The position of the first byte. Default is 0, or the first byte. */ #define WSLUA_OPTARG_ByteArray_le_int_LENGTH 3 /* The length of the integer. Default is -1, or the remaining bytes in the <<lua_class_ByteArray,`ByteArray`>>. */ @@ -230,7 +227,7 @@ WSLUA_METHOD ByteArray_le_int(lua_State* L) { int offset = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_le_int_OFFSET, 0); int len = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_le_int_LENGTH, -1); - if (offset < 0 || (guint)offset >= ba->len) { + if (offset < 0 || (unsigned)offset >= ba->len) { luaL_argerror(L, WSLUA_OPTARG_ByteArray_le_int_OFFSET, "offset out of bounds"); return 0; } @@ -244,18 +241,18 @@ WSLUA_METHOD ByteArray_le_int(lua_State* L) { return 0; } - if ((guint)(offset + len) > ba->len) { - luaL_error(L, "range out of bounds");; + if ((unsigned)(offset + len) > ba->len) { + luaL_error(L, "range out of bounds"); return 0; } - gint32 value = (gint8)ba->data[offset + len - 1]; + int32_t value = (int8_t)ba->data[offset + len - 1]; for (int i = len - 2; i >= 0; i--) { value <<= 8; - value |= (guint8)ba->data[offset + i]; + value |= (uint8_t)ba->data[offset + i]; } - lua_pushnumber(L, value); + lua_pushinteger(L, value); WSLUA_RETURN(1); /* The value of the little endian encoded signed integer beginning at given offset with given length. */ } @@ -263,7 +260,7 @@ WSLUA_METHOD ByteArray_le_int(lua_State* L) { WSLUA_METHOD ByteArray_le_int64(lua_State* L) { /* Read a little endian encoded 64 bit signed integer in a <<lua_class_ByteArray,`ByteArray`>> beginning at given offset with given length. - @since 4.1.0 + @since 4.2.0 */ #define WSLUA_OPTARG_ByteArray_le_int64_OFFSET 2 /* The position of the first byte. Default is 0, or the first byte. */ #define WSLUA_OPTARG_ByteArray_le_int64_LENGTH 3 /* The length of the integer. Default is -1, or the remaining bytes in the <<lua_class_ByteArray,`ByteArray`>>. */ @@ -271,7 +268,7 @@ WSLUA_METHOD ByteArray_le_int64(lua_State* L) { int offset = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_le_int64_OFFSET, 0); int len = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_le_int64_LENGTH, -1); - if (offset < 0 || (guint)offset >= ba->len) { + if (offset < 0 || (unsigned)offset >= ba->len) { luaL_argerror(L, WSLUA_OPTARG_ByteArray_le_int64_OFFSET, "offset out of bounds"); return 0; } @@ -285,15 +282,15 @@ WSLUA_METHOD ByteArray_le_int64(lua_State* L) { return 0; } - if ((guint)(offset + len) > ba->len) { - luaL_error(L, "range out of bounds");; + if ((unsigned)(offset + len) > ba->len) { + luaL_error(L, "range out of bounds"); return 0; } - gint64 value = (gint8)ba->data[offset + len - 1]; + int64_t value = (int8_t)ba->data[offset + len - 1]; for (int i = len - 2; i >= 0; i--) { value <<= 8; - value |= (guint8)ba->data[offset + i]; + value |= (uint8_t)ba->data[offset + i]; } pushInt64(L, value); @@ -304,7 +301,7 @@ WSLUA_METHOD ByteArray_le_int64(lua_State* L) { WSLUA_METHOD ByteArray_le_uint(lua_State* L) { /* Read a little endian encoded unsigned integer in a <<lua_class_ByteArray,`ByteArray`>> beginning at given offset with given length. - @since 4.1.0 + @since 4.2.0 */ #define WSLUA_OPTARG_ByteArray_le_uint_OFFSET 2 /* The position of the first byte. Default is 0, or the first byte. */ #define WSLUA_OPTARG_ByteArray_le_uint_LENGTH 3 /* The length of the integer. Default is -1, or the remaining bytes in the <<lua_class_ByteArray,`ByteArray`>>. */ @@ -312,7 +309,7 @@ WSLUA_METHOD ByteArray_le_uint(lua_State* L) { int offset = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_le_uint_OFFSET, 0); int len = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_le_uint_LENGTH, -1); - if (offset < 0 || (guint)offset >= ba->len) { + if (offset < 0 || (unsigned)offset >= ba->len) { luaL_argerror(L, WSLUA_OPTARG_ByteArray_le_uint_OFFSET, "offset out of bounds"); return 0; } @@ -326,18 +323,18 @@ WSLUA_METHOD ByteArray_le_uint(lua_State* L) { return 0; } - if ((guint)(offset + len) > ba->len) { - luaL_error(L, "range out of bounds");; + if ((unsigned)(offset + len) > ba->len) { + luaL_error(L, "range out of bounds"); return 0; } - guint32 value = (guint8)ba->data[offset + len - 1]; + uint32_t value = (uint8_t)ba->data[offset + len - 1]; for (int i = len - 2; i >= 0; i--) { value <<= 8; - value |= (guint8)ba->data[offset + i]; + value |= (uint8_t)ba->data[offset + i]; } - lua_pushnumber(L, value); + lua_pushinteger(L, value); WSLUA_RETURN(1); /* The value of the little endian encoded unsigned integer beginning at given offset with given length. */ } @@ -345,7 +342,7 @@ WSLUA_METHOD ByteArray_le_uint(lua_State* L) { WSLUA_METHOD ByteArray_le_uint64(lua_State* L) { /* Read a little endian encoded 64 bit unsigned integer in a <<lua_class_ByteArray,`ByteArray`>> beginning at given offset with given length. - @since 4.1.0 + @since 4.2.0 */ #define WSLUA_OPTARG_ByteArray_le_uint64_OFFSET 2 /* The position of the first byte. Default is 0, or the first byte. */ #define WSLUA_OPTARG_ByteArray_le_uint64_LENGTH 3 /* The length of the integer. Default is -1, or the remaining bytes in the <<lua_class_ByteArray,`ByteArray`>>. */ @@ -353,7 +350,7 @@ WSLUA_METHOD ByteArray_le_uint64(lua_State* L) { int offset = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_le_uint64_OFFSET, 0); int len = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_le_uint64_LENGTH, -1); - if (offset < 0 || (guint)offset >= ba->len) { + if (offset < 0 || (unsigned)offset >= ba->len) { luaL_argerror(L, WSLUA_OPTARG_ByteArray_le_uint64_OFFSET, "offset out of bounds"); return 0; } @@ -367,15 +364,15 @@ WSLUA_METHOD ByteArray_le_uint64(lua_State* L) { return 0; } - if ((guint)(offset + len) > ba->len) { - luaL_error(L, "range out of bounds");; + if ((unsigned)(offset + len) > ba->len) { + luaL_error(L, "range out of bounds"); return 0; } - guint64 value = (guint8)ba->data[offset + len - 1]; + uint64_t value = (uint8_t)ba->data[offset + len - 1]; for (int i = len - 2; i >= 0; i--) { value <<= 8; - value |= (guint8)ba->data[offset + i]; + value |= (uint8_t)ba->data[offset + i]; } pushUInt64(L, value); @@ -386,7 +383,7 @@ WSLUA_METHOD ByteArray_le_uint64(lua_State* L) { WSLUA_METHOD ByteArray_int(lua_State* L) { /* Read a big endian encoded signed integer in a <<lua_class_ByteArray,`ByteArray`>> beginning at given offset with given length. - @since 4.1.0 + @since 4.2.0 */ #define WSLUA_OPTARG_ByteArray_int_OFFSET 2 /* The position of the first byte. Default is 0, or the first byte. */ #define WSLUA_OPTARG_ByteArray_int_LENGTH 3 /* The length of the integer. Default is -1, or the remaining bytes in the <<lua_class_ByteArray,`ByteArray`>>. */ @@ -394,7 +391,7 @@ WSLUA_METHOD ByteArray_int(lua_State* L) { int offset = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_int_OFFSET, 0); int len = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_int_LENGTH, -1); - if (offset < 0 || (guint)offset >= ba->len) { + if (offset < 0 || (unsigned)offset >= ba->len) { luaL_argerror(L, WSLUA_OPTARG_ByteArray_int_OFFSET, "offset out of bounds"); return 0; } @@ -408,18 +405,18 @@ WSLUA_METHOD ByteArray_int(lua_State* L) { return 0; } - if ((guint)(offset + len) > ba->len) { - luaL_error(L, "range out of bounds");; + if ((unsigned)(offset + len) > ba->len) { + luaL_error(L, "range out of bounds"); return 0; } - gint32 value = (gint8)ba->data[offset]; + int32_t value = (int8_t)ba->data[offset]; for (int i = 1; i < len; i++) { value <<= 8; - value |= (guint8)ba->data[offset + i]; + value |= (uint8_t)ba->data[offset + i]; } - lua_pushnumber(L, value); + lua_pushinteger(L, value); WSLUA_RETURN(1); /* The value of the big endian encoded 32 bit signed integer beginning at given offset with given length. */ } @@ -427,7 +424,7 @@ WSLUA_METHOD ByteArray_int(lua_State* L) { WSLUA_METHOD ByteArray_int64(lua_State* L) { /* Read a big endian encoded 64 bit signed integer in a <<lua_class_ByteArray,`ByteArray`>> beginning at given offset with given length. - @since 4.1.0 + @since 4.2.0 */ #define WSLUA_OPTARG_ByteArray_int64_OFFSET 2 /* The position of the first byte. Default is 0, or the first byte. */ #define WSLUA_OPTARG_ByteArray_int64_LENGTH 3 /* The length of the integer. Default is -1, or the remaining bytes in the <<lua_class_ByteArray,`ByteArray`>>. */ @@ -435,7 +432,7 @@ WSLUA_METHOD ByteArray_int64(lua_State* L) { int offset = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_int64_OFFSET, 0); int len = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_int64_LENGTH, -1); - if (offset < 0 || (guint)offset >= ba->len) { + if (offset < 0 || (unsigned)offset >= ba->len) { luaL_argerror(L, WSLUA_OPTARG_ByteArray_int64_OFFSET, "offset out of bounds"); return 0; } @@ -449,15 +446,15 @@ WSLUA_METHOD ByteArray_int64(lua_State* L) { return 0; } - if ((guint)(offset + len) > ba->len) { - luaL_error(L, "range out of bounds");; + if ((unsigned)(offset + len) > ba->len) { + luaL_error(L, "range out of bounds"); return 0; } - gint64 value = (gint8)ba->data[offset]; + int64_t value = (int8_t)ba->data[offset]; for (int i = 1; i < len; i++) { value <<= 8; - value |= (guint8)ba->data[offset + i]; + value |= (uint8_t)ba->data[offset + i]; } pushInt64(L, value); @@ -468,7 +465,7 @@ WSLUA_METHOD ByteArray_int64(lua_State* L) { WSLUA_METHOD ByteArray_uint(lua_State* L) { /* Read a big endian encoded unsigned integer in a <<lua_class_ByteArray,`ByteArray`>> beginning at given offset with given length. - @since 4.1.0 + @since 4.2.0 */ #define WSLUA_OPTARG_ByteArray_uint_OFFSET 2 /* The position of the first byte. Default is 0, or the first byte. */ #define WSLUA_OPTARG_ByteArray_uint_LENGTH 3 /* The length of the integer. Default is -1, or the remaining bytes in the <<lua_class_ByteArray,`ByteArray`>>. */ @@ -476,7 +473,7 @@ WSLUA_METHOD ByteArray_uint(lua_State* L) { int offset = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_uint_OFFSET, 0); int len = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_uint_LENGTH, -1); - if (offset < 0 || (guint)offset >= ba->len) { + if (offset < 0 || (unsigned)offset >= ba->len) { luaL_argerror(L, WSLUA_OPTARG_ByteArray_uint_OFFSET, "offset out of bounds"); return 0; } @@ -490,18 +487,18 @@ WSLUA_METHOD ByteArray_uint(lua_State* L) { return 0; } - if ((guint)(offset + len) > ba->len) { - luaL_error(L, "range out of bounds");; + if ((unsigned)(offset + len) > ba->len) { + luaL_error(L, "range out of bounds"); return 0; } - guint32 value = (guint8)ba->data[offset]; + uint32_t value = (uint8_t)ba->data[offset]; for (int i = 1; i < len; i++) { value <<= 8; - value |= (guint8)ba->data[offset + i]; + value |= (uint8_t)ba->data[offset + i]; } - lua_pushnumber(L, value); + lua_pushinteger(L, value); WSLUA_RETURN(1); /* The value of the big endian encoded 32 bit unsigned integer beginning at given offset with given length. */ } @@ -509,7 +506,7 @@ WSLUA_METHOD ByteArray_uint(lua_State* L) { WSLUA_METHOD ByteArray_uint64(lua_State* L) { /* Read a big endian encoded 64 bit unsigned integer in a <<lua_class_ByteArray,`ByteArray`>> beginning at given offset with given length. - @since 4.1.0 + @since 4.2.0 */ #define WSLUA_OPTARG_ByteArray_uint64_OFFSET 2 /* The position of the first byte. Default is 0, or the first byte. */ #define WSLUA_OPTARG_ByteArray_uint64_LENGTH 3 /* The length of the integer. Default is -1, or the remaining bytes in the <<lua_class_ByteArray,`ByteArray`>>. */ @@ -517,7 +514,7 @@ WSLUA_METHOD ByteArray_uint64(lua_State* L) { int offset = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_uint64_OFFSET, 0); int len = (int)luaL_optinteger(L, WSLUA_OPTARG_ByteArray_uint64_LENGTH, -1); - if (offset < 0 || (guint)offset >= ba->len) { + if (offset < 0 || (unsigned)offset >= ba->len) { luaL_argerror(L, WSLUA_OPTARG_ByteArray_uint64_OFFSET, "offset out of bounds"); return 0; } @@ -531,15 +528,15 @@ WSLUA_METHOD ByteArray_uint64(lua_State* L) { return 0; } - if ((guint)(offset + len) > ba->len) { - luaL_error(L, "range out of bounds");; + if ((unsigned)(offset + len) > ba->len) { + luaL_error(L, "range out of bounds"); return 0; } - guint64 value = (guint8)ba->data[offset]; + uint64_t value = (uint8_t)ba->data[offset]; for (int i = 1; i < len; i++) { value <<= 8; - value |= (guint8)ba->data[offset + i]; + value |= (uint8_t)ba->data[offset + i]; } pushUInt64(L, value); @@ -551,7 +548,7 @@ WSLUA_METHOD ByteArray_len(lua_State* L) { /* Obtain the length of a <<lua_class_ByteArray,`ByteArray`>>. */ ByteArray ba = checkByteArray(L,1); - lua_pushnumber(L,(lua_Number)ba->len); + lua_pushinteger(L,(lua_Integer)ba->len); WSLUA_RETURN(1); /* The length of the <<lua_class_ByteArray,`ByteArray`>>. */ } @@ -579,14 +576,11 @@ WSLUA_METHOD ByteArray_subset(lua_State* L) { } WSLUA_METHOD ByteArray_base64_decode(lua_State* L) { - /* Obtain a Base64 decoded <<lua_class_ByteArray,`ByteArray`>>. - - @since 1.11.3 - */ + /* Obtain a Base64 decoded <<lua_class_ByteArray,`ByteArray`>>. */ ByteArray ba = checkByteArray(L,1); ByteArray ba2; - gchar *data; - gsize len = ba->len; + char *data; + size_t len = ba->len; if ((len % 4) != 0) { len += 4 - (len % 4); @@ -594,7 +588,7 @@ WSLUA_METHOD ByteArray_base64_decode(lua_State* L) { ba2 = g_byte_array_new(); if (ba->len > 1) { - data = (gchar*)g_malloc(len + 1); + data = (char*)g_malloc(len + 1); memcpy(data, ba->data, ba->len); if (len > ba->len) { memcpy(data + ba->len, "====", len - ba->len); @@ -611,14 +605,11 @@ WSLUA_METHOD ByteArray_base64_decode(lua_State* L) { } WSLUA_METHOD ByteArray_raw(lua_State* L) { - /* Obtain a Lua string of the binary bytes in a <<lua_class_ByteArray,`ByteArray`>>. - - @since 1.11.3 - */ + /* Obtain a Lua string of the binary bytes in a <<lua_class_ByteArray,`ByteArray`>>. */ #define WSLUA_OPTARG_ByteArray_raw_OFFSET 2 /* The position of the first byte (default=0/first). */ #define WSLUA_OPTARG_ByteArray_raw_LENGTH 3 /* The length of the segment to get (default=all). */ ByteArray ba = checkByteArray(L,1); - guint offset = (guint) luaL_optinteger(L,WSLUA_OPTARG_ByteArray_raw_OFFSET,0); + unsigned offset = (unsigned) luaL_optinteger(L,WSLUA_OPTARG_ByteArray_raw_OFFSET,0); int len; if (!ba) return 0; @@ -628,7 +619,7 @@ WSLUA_METHOD ByteArray_raw(lua_State* L) { } len = (int) luaL_optinteger(L,WSLUA_OPTARG_ByteArray_raw_LENGTH, ba->len - offset); - if ((len < 0) || ((guint)len > (ba->len - offset))) + if ((len < 0) || ((unsigned)len > (ba->len - offset))) len = ba->len - offset; lua_pushlstring(L, &(ba->data[offset]), len); @@ -637,19 +628,16 @@ WSLUA_METHOD ByteArray_raw(lua_State* L) { } WSLUA_METHOD ByteArray_tohex(lua_State* L) { - /* Obtain a Lua string of the bytes in a <<lua_class_ByteArray,`ByteArray`>> as hex-ascii, with given separator - - @since 1.11.3 - */ + /* Obtain a Lua string of the bytes in a <<lua_class_ByteArray,`ByteArray`>> as hex-ascii, with given separator. */ #define WSLUA_OPTARG_ByteArray_tohex_LOWERCASE 2 /* True to use lower-case hex characters (default=false). */ #define WSLUA_OPTARG_ByteArray_tohex_SEPARATOR 3 /* A string separator to insert between hex bytes (default=nil). */ ByteArray ba = checkByteArray(L,1); - gboolean lowercase = FALSE; - const gchar* sep = NULL; + bool lowercase = false; + const char* sep = NULL; if (!ba) return 0; - lowercase = wslua_optbool(L,WSLUA_OPTARG_ByteArray_tohex_LOWERCASE,FALSE); + lowercase = wslua_optbool(L,WSLUA_OPTARG_ByteArray_tohex_LOWERCASE,false); sep = luaL_optstring(L,WSLUA_OPTARG_ByteArray_tohex_SEPARATOR,NULL); wslua_bin2hex(L, ba->data, ba->len, lowercase, sep); @@ -664,7 +652,7 @@ WSLUA_METAMETHOD ByteArray__tostring(lua_State* L) { if (!ba) return 0; - wslua_bin2hex(L, ba->data, ba->len, FALSE, NULL); + wslua_bin2hex(L, ba->data, ba->len, false, NULL); WSLUA_RETURN(1); /* A hex-ascii string representation of the <<lua_class_ByteArray,`ByteArray`>>. */ } @@ -690,8 +678,8 @@ WSLUA_METHOD ByteArray_tvb (lua_State *L) { */ #define WSLUA_ARG_ByteArray_tvb_NAME 2 /* The name to be given to the new data source. */ ByteArray ba = checkByteArray(L,1); - const gchar* name = luaL_optstring(L,WSLUA_ARG_ByteArray_tvb_NAME,"Unnamed") ; - guint8* data; + const char* name = luaL_optstring(L,WSLUA_ARG_ByteArray_tvb_NAME,"Unnamed") ; + uint8_t* data; Tvb tvb; if (!lua_tvb) { @@ -699,12 +687,12 @@ WSLUA_METHOD ByteArray_tvb (lua_State *L) { return 0; } - data = (guint8 *)g_memdup2(ba->data, ba->len); + data = (uint8_t *)g_memdup2(ba->data, ba->len); tvb = (Tvb)g_malloc(sizeof(struct _wslua_tvb)); tvb->ws_tvb = tvb_new_child_real_data(lua_tvb, data, ba->len,ba->len); - tvb->expired = FALSE; - tvb->need_free = FALSE; + tvb->expired = false; + tvb->need_free = false; tvb_set_free_cb(tvb->ws_tvb, g_free); add_new_data_source(lua_pinfo, tvb->ws_tvb, name); diff --git a/epan/wslua/wslua_capture_info.c b/epan/wslua/wslua_capture_info.c index 06bf847d..6fb25784 100644 --- a/epan/wslua/wslua_capture_info.c +++ b/epan/wslua/wslua_capture_info.c @@ -33,11 +33,9 @@ WSLUA_CLASS_DEFINE(CaptureInfo,FAIL_ON_NULL_OR_EXPIRED("CaptureInfo")); In other words, when the Lua plugin's `FileHandler.read_open()` function is invoked, a `CaptureInfo` object will be passed in as one of the arguments, and its fields should be written to by your Lua code to tell Wireshark about the capture. - - @since 1.11.3 */ -CaptureInfo* push_CaptureInfo(lua_State* L, wtap *wth, const gboolean first_time) { +CaptureInfo* push_CaptureInfo(lua_State* L, wtap *wth, const bool first_time) { CaptureInfo f; if (!wth) { @@ -48,7 +46,7 @@ CaptureInfo* push_CaptureInfo(lua_State* L, wtap *wth, const gboolean first_time f = (CaptureInfo) g_malloc0(sizeof(struct _wslua_captureinfo)); f->wth = wth; f->wdh = NULL; - f->expired = FALSE; + f->expired = false; if (first_time) { /* XXX: need to do this? */ @@ -87,22 +85,22 @@ static int CaptureInfo__gc(lua_State* L) { See `wtap_encaps` for available types. Set to `wtap_encaps.PER_PACKET` if packets can have different types, then later set `FrameInfo.encap` for each packet during `read()`/`seek_read()`. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,encap,wth->file_encap); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,encap,wth->file_encap,int); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(CaptureInfo,encap,wth->file_encap); +WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(CaptureInfo,encap,wth->file_encap,int); /* WSLUA_ATTRIBUTE CaptureInfo_time_precision RW The precision of the packet timestamps in the file. See `wtap_file_tsprec` for available precisions. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,time_precision,wth->file_tsprec); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,time_precision,wth->file_tsprec,int); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(CaptureInfo,time_precision,wth->file_tsprec); +WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(CaptureInfo,time_precision,wth->file_tsprec,int); /* WSLUA_ATTRIBUTE CaptureInfo_snapshot_length RW The maximum packet length that could be recorded. Setting it to `0` means unknown. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfo,snapshot_length,wth->snapshot_length); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,snapshot_length,wth->snapshot_length,guint); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(CaptureInfo,snapshot_length,wth->snapshot_length); +WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(CaptureInfo,snapshot_length,wth->snapshot_length,unsigned); /* WSLUA_ATTRIBUTE CaptureInfo_comment RW A string comment for the whole capture file, or nil if there is no `comment`. */ @@ -147,7 +145,7 @@ static int CaptureInfo_set_hosts(lua_State* L) { const char *name = NULL; size_t addr_len = 0; size_t name_len = 0; - guint32 v4_addr = 0; + uint32_t v4_addr = 0; ws_in6_addr v6_addr = { {0} }; if (!wth->add_new_ipv4 || !wth->add_new_ipv6) { @@ -167,30 +165,30 @@ static int CaptureInfo_set_hosts(lua_State* L) { while (lua_next(L, -2) != 0) { /* 'key' (at index -2) and 'value' (at index -1) */ if (!lua_istable(L,-1)) { - lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ + lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addresses table */ return luaL_error(L, "CaptureInfo.host ipv4_addresses table does not contain a table"); } lua_getfield(L, -1, "addr"); if (!lua_isstring(L,-1)) { - lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ + lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addresses table */ return luaL_error(L, "CaptureInfo.host ipv4_addresses table's table does not contain an 'addr' field"); } addr = luaL_checklstring(L,-1,&addr_len); if (addr_len != 4) { - lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ + lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addresses table */ return luaL_error(L, "CaptureInfo.host ipv4_addresses 'addr' value is not 4 bytes long"); } memcpy(&v4_addr, addr, 4); lua_getfield(L, -1, "name"); if (!lua_isstring(L,-1)) { - lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ + lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addresses table */ return luaL_error(L, "CaptureInfo.host ipv4_addresses table's table does not contain an 'addr' field"); } name = luaL_checklstring(L,-1,&name_len); - wth->add_new_ipv4(v4_addr, name, FALSE); + wth->add_new_ipv4(v4_addr, name, false); /* removes 'value'; keeps 'key' for next iteration */ lua_pop(L, 1); @@ -210,30 +208,30 @@ static int CaptureInfo_set_hosts(lua_State* L) { while (lua_next(L, -2) != 0) { /* 'key' (at index -2) and 'value' (at index -1) */ if (!lua_istable(L,-1)) { - lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ + lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addresses table */ return luaL_error(L, "CaptureInfo.host ipv6_addresses table does not contain a table"); } lua_getfield(L, -1, "addr"); if (!lua_isstring(L,-1)) { - lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ + lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addresses table */ return luaL_error(L, "CaptureInfo.host ipv6_addresses table's table does not contain an 'addr' field"); } addr = luaL_checklstring(L,-1,&addr_len); if (addr_len != 16) { - lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ + lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addresses table */ return luaL_error(L, "CaptureInfo.host ipv6_addresses 'addr' value is not 16 bytes long"); } memcpy(&v6_addr, addr, 16); lua_getfield(L, -1, "name"); if (!lua_isstring(L,-1)) { - lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addreses table */ + lua_pop(L, 3); /* remove whatever it is, the key, and the ipv4_addresses table */ return luaL_error(L, "CaptureInfo.host ipv6_addresses table's table does not contain an 'addr' field"); } name = luaL_checklstring(L,-1,&name_len); - wth->add_new_ipv6((const void *)(&v6_addr), name, FALSE); + wth->add_new_ipv6((const void *)(&v6_addr), name, false); /* removes 'value'; keeps 'key' for next iteration */ lua_pop(L, 1); @@ -309,8 +307,6 @@ WSLUA_CLASS_DEFINE(CaptureInfoConst,FAIL_ON_NULL_OR_EXPIRED("CaptureInfoConst")) In other words, when the Lua plugin's FileHandler `write_open` function is invoked, a `CaptureInfoConst` object will be passed in as one of the arguments, and its fields should be read from by your Lua code to get data about the capture that needs to be written. - - @since 1.11.3 */ CaptureInfoConst* push_CaptureInfoConst(lua_State* L, wtap_dumper *wdh) { @@ -324,7 +320,7 @@ CaptureInfoConst* push_CaptureInfoConst(lua_State* L, wtap_dumper *wdh) { f = (CaptureInfoConst) g_malloc0(sizeof(struct _wslua_captureinfo)); f->wth = NULL; f->wdh = wdh; - f->expired = FALSE; + f->expired = false; return pushCaptureInfoConst(L,f); } @@ -344,18 +340,18 @@ WSLUA_METAMETHOD CaptureInfoConst__tostring(lua_State* L) { } /* WSLUA_ATTRIBUTE CaptureInfoConst_type RO The file type. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfoConst,type,wdh->file_type_subtype); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(CaptureInfoConst,type,wdh->file_type_subtype); /* WSLUA_ATTRIBUTE CaptureInfoConst_snapshot_length RO The maximum packet length that is actually recorded (vs. the original length of any given packet on-the-wire). A value of `0` means the snapshot length is unknown or there is no one such length for the whole file. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfoConst,snapshot_length,wdh->snaplen); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(CaptureInfoConst,snapshot_length,wdh->snaplen); /* WSLUA_ATTRIBUTE CaptureInfoConst_encap RO The packet encapsulation type for the whole file. See `wtap_encaps` for available types. It is set to `wtap_encaps.PER_PACKET` if packets can have different types, in which case each Frame identifies its type, in `FrameInfo.packet_encap`. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfoConst,encap,wdh->file_encap); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(CaptureInfoConst,encap,wdh->file_encap); /* WSLUA_ATTRIBUTE CaptureInfoConst_comment RW A comment for the whole capture file, if the `wtap_presence_flags.COMMENTS` was set in the presence flags; nil if there is no comment. */ diff --git a/epan/wslua/wslua_column.c b/epan/wslua/wslua_column.c index 5ae0c4cc..b5712299 100644 --- a/epan/wslua/wslua_column.c +++ b/epan/wslua/wslua_column.c @@ -22,11 +22,11 @@ /* WSLUA_CONTINUE_MODULE Pinfo */ -static GPtrArray* outstanding_Column = NULL; -static GPtrArray* outstanding_Columns = NULL; +static GPtrArray* outstanding_Column; +static GPtrArray* outstanding_Columns; -CLEAR_OUTSTANDING(Column,expired, TRUE) -CLEAR_OUTSTANDING(Columns,expired, TRUE) +CLEAR_OUTSTANDING(Column,expired, true) +CLEAR_OUTSTANDING(Columns,expired, true) #define PUSH_COLUMN(L,c) {g_ptr_array_add(outstanding_Column,c);pushColumn(L,c);} @@ -40,11 +40,11 @@ void Push_Columns(lua_State *L, Columns c) WSLUA_CLASS_DEFINE(Column,FAIL_ON_NULL("Column")); /* A Column in the packet list. */ struct col_names_t { - const gchar* name; + const char* name; int id; }; -// Duplicated belown in Columns__newindex. +// Duplicated below in Columns__newindex. static const struct col_names_t colnames[] = { {"number",COL_NUMBER}, {"abs_time",COL_ABS_TIME}, @@ -91,7 +91,7 @@ static const struct col_names_t colnames[] = { {NULL,0} }; -static gint col_name_to_id(const gchar* name) { +static int col_name_to_id(const char* name) { const struct col_names_t* cn; for(cn = colnames; cn->name; cn++) { if (g_str_equal(cn->name,name)) { @@ -102,7 +102,7 @@ static gint col_name_to_id(const gchar* name) { return 0; } -static const gchar* col_id_to_name(gint id) { +static const char* col_id_to_name(int id) { const struct col_names_t* cn; for(cn = colnames; cn->name; cn++) { if ( cn->id == id ) { @@ -115,7 +115,7 @@ static const gchar* col_id_to_name(gint id) { WSLUA_METAMETHOD Column__tostring(lua_State *L) { Column c = checkColumn(L,1); - const gchar* text; + const char* text; if (!c->cinfo) { text = col_id_to_name(c->col); @@ -136,7 +136,7 @@ static int Column__gc(lua_State* L) { if (!col) return 0; if (!col->expired) - col->expired = TRUE; + col->expired = true; else g_free(col); @@ -159,7 +159,7 @@ WSLUA_METHOD Column_set(lua_State *L) { /* Sets the text of a Column. */ #define WSLUA_ARG_Column_set_TEXT 2 /* The text to which to set the Column. */ Column c = checkColumn(L,1); - const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_set_TEXT); + const char* s = luaL_checkstring(L,WSLUA_ARG_Column_set_TEXT); if (!(c->cinfo)) return 0; @@ -173,7 +173,7 @@ WSLUA_METHOD Column_append(lua_State *L) { /* Appends text to a Column. */ #define WSLUA_ARG_Column_append_TEXT 2 /* The text to append to the Column. */ Column c = checkColumn(L,1); - const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_append_TEXT); + const char* s = luaL_checkstring(L,WSLUA_ARG_Column_append_TEXT); if (!(c->cinfo)) return 0; @@ -187,7 +187,7 @@ WSLUA_METHOD Column_prepend(lua_State *L) { /* Prepends text to a Column. */ #define WSLUA_ARG_Column_prepend_TEXT 2 /* The text to prepend to the Column. */ Column c = checkColumn(L,1); - const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_prepend_TEXT); + const char* s = luaL_checkstring(L,WSLUA_ARG_Column_prepend_TEXT); if (!(c->cinfo)) return 0; @@ -198,10 +198,7 @@ WSLUA_METHOD Column_prepend(lua_State *L) { } WSLUA_METHOD Column_fence(lua_State *L) { - /* Sets Column text fence, to prevent overwriting. - - @since 1.10.6 - */ + /* Sets Column text fence, to prevent overwriting. */ Column c = checkColumn(L,1); if (c->cinfo) @@ -211,10 +208,7 @@ WSLUA_METHOD Column_fence(lua_State *L) { } WSLUA_METHOD Column_clear_fence(lua_State *L) { - /* Clear Column text fence. - - @since 1.11.3 - */ + /* Clear Column text fence. */ Column c = checkColumn(L,1); if (c->cinfo) @@ -244,6 +238,9 @@ WSLUA_META Column_meta[] = { int Column_register(lua_State *L) { WSLUA_REGISTER_CLASS(Column); + if (outstanding_Column != NULL) { + g_ptr_array_unref(outstanding_Column); + } outstanding_Column = g_ptr_array_new(); return 0; } @@ -361,7 +358,7 @@ WSLUA_METAMETHOD Columns__index(lua_State *L) { Column c = (Column)g_malloc(sizeof(struct _wslua_col_info)); c->cinfo = NULL; c->col = col_name_to_id(colname); - c->expired = FALSE; + c->expired = false; PUSH_COLUMN(L,c); return 1; @@ -378,7 +375,7 @@ WSLUA_METAMETHOD Columns__index(lua_State *L) { Column c = (Column)g_malloc(sizeof(struct _wslua_col_info)); c->cinfo = cols->cinfo; c->col = col_name_to_id(colname); - c->expired = FALSE; + c->expired = false; PUSH_COLUMN(L,c); return 1; @@ -402,7 +399,7 @@ static int Columns__gc(lua_State* L) { if (!cols) return 0; if (!cols->expired) - cols->expired = TRUE; + cols->expired = true; else g_free(cols); @@ -421,6 +418,9 @@ WSLUA_META Columns_meta[] = { int Columns_register(lua_State *L) { WSLUA_REGISTER_META(Columns); + if (outstanding_Columns != NULL) { + g_ptr_array_unref(outstanding_Columns); + } outstanding_Columns = g_ptr_array_new(); return 0; } diff --git a/epan/wslua/wslua_dir.c b/epan/wslua/wslua_dir.c index 542ce0a6..4049d780 100644 --- a/epan/wslua/wslua_dir.c +++ b/epan/wslua/wslua_dir.c @@ -29,8 +29,6 @@ WSLUA_CONSTRUCTOR Dir_make(lua_State* L) { If the directory was created successfully, a boolean `true` is returned. If the directory cannot be made because it already exists, `false` is returned. If the directory cannot be made because an error occurred, `nil` is returned. - - @since 1.11.3 */ #define WSLUA_ARG_Dir_make_NAME 1 /* The name of the directory, possibly including path. */ @@ -58,8 +56,6 @@ WSLUA_CONSTRUCTOR Dir_exists(lua_State* L) { If the directory exists, a boolean `true` is returned. If the path is a file instead, `false` is returned. If the path does not exist or an error occurred, `nil` is returned. - - @since 1.11.3 */ #define WSLUA_ARG_Dir_exists_NAME 1 /* The name of the directory, possibly including path. */ @@ -88,8 +84,6 @@ WSLUA_CONSTRUCTOR Dir_remove(lua_State* L) { This function only removes empty directories. To remove a directory regardless, use `Dir.remove_all()`. - - @since 1.11.3 */ #define WSLUA_ARG_Dir_remove_NAME 1 /* The name of the directory, possibly including path. */ @@ -113,7 +107,7 @@ WSLUA_CONSTRUCTOR Dir_remove(lua_State* L) { static int delete_directory(const char *directory) { WS_DIR *dir; WS_DIRENT *file; - gchar *filename; + char *filename; int ret = 0; /* delete all contents of directory */ @@ -148,8 +142,6 @@ WSLUA_CONSTRUCTOR Dir_remove_all(lua_State* L) { If the directory was removed successfully, a boolean `true` is returned. If the directory cannot be removed because it does not exist, `false` is returned. If the directory cannot be removed because an error occurred, `nil` is returned. - - @since 1.11.3 */ #define WSLUA_ARG_Dir_remove_all_NAME 1 /* The name of the directory, possibly including path. */ @@ -236,8 +228,8 @@ WSLUA_METAMETHOD Dir__call(lua_State* L) { */ Dir dir = checkDir(L,1); - const gchar* file; - const gchar* filename; + const char* file; + const char* filename; const char* ext; if (!dir->dir) { @@ -285,13 +277,10 @@ WSLUA_METHOD Dir_close(lua_State* L) { } WSLUA_CONSTRUCTOR Dir_personal_config_path(lua_State* L) { - /* Gets the https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html[personal configuration] directory path, with filename if supplied. - - @since 1.11.3 - */ + /* Gets the https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html[personal configuration] directory path, with filename if supplied. */ #define WSLUA_OPTARG_Dir_personal_config_path_FILENAME 1 /* A filename. */ const char *fname = luaL_optstring(L, WSLUA_OPTARG_Dir_personal_config_path_FILENAME,""); - char* filename = get_persconffile_path(fname,FALSE); + char* filename = get_persconffile_path(fname,false); lua_pushstring(L,filename); g_free(filename); @@ -299,10 +288,7 @@ WSLUA_CONSTRUCTOR Dir_personal_config_path(lua_State* L) { } WSLUA_CONSTRUCTOR Dir_global_config_path(lua_State* L) { - /* Gets the https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html[global configuration] directory path, with filename if supplied. - - @since 1.11.3 - */ + /* Gets the https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html[global configuration] directory path, with filename if supplied. */ #define WSLUA_OPTARG_Dir_global_config_path_FILENAME 1 /* A filename */ const char *fname = luaL_optstring(L, WSLUA_OPTARG_Dir_global_config_path_FILENAME,""); char* filename; @@ -314,19 +300,13 @@ WSLUA_CONSTRUCTOR Dir_global_config_path(lua_State* L) { } WSLUA_CONSTRUCTOR Dir_personal_plugins_path(lua_State* L) { - /* Gets the personal plugins directory path. - - @since 1.11.3 - */ + /* Gets the personal plugins directory path. */ lua_pushstring(L, get_plugins_pers_dir()); WSLUA_RETURN(1); /* The pathname of the https://www.wireshark.org/docs/wsug_html_chunked/ChPluginFolders.html[personal plugins] directory. */ } WSLUA_CONSTRUCTOR Dir_global_plugins_path(lua_State* L) { - /* Gets the global plugins directory path. - - @since 1.11.3 - */ + /* Gets the global plugins directory path. */ lua_pushstring(L, get_plugins_dir()); WSLUA_RETURN(1); /* The pathname of the https://www.wireshark.org/docs/wsug_html_chunked/ChPluginFolders.html[global plugins] directory. */ } diff --git a/epan/wslua/wslua_dissector.c b/epan/wslua/wslua_dissector.c index 4fb7a9a1..4f302f77 100644 --- a/epan/wslua/wslua_dissector.c +++ b/epan/wslua/wslua_dissector.c @@ -17,11 +17,16 @@ #include "config.h" +#include <stdint.h> +#include "epan/guid-utils.h" +#include "epan/proto.h" #include "wslua.h" #include <epan/decode_as.h> #include <epan/exceptions.h> #include <epan/show_exception.h> +#include <epan/dissectors/packet-dcerpc.h> +#include <string.h> /* WSLUA_CONTINUE_MODULE Proto */ @@ -35,7 +40,7 @@ WSLUA_CLASS_DEFINE(Dissector,NOP); WSLUA_CONSTRUCTOR Dissector_get (lua_State *L) { /* Obtains a dissector reference by name. */ #define WSLUA_ARG_Dissector_get_NAME 1 /* The name of the dissector. */ - const gchar* name = luaL_checkstring(L,WSLUA_ARG_Dissector_get_NAME); + const char* name = luaL_checkstring(L,WSLUA_ARG_Dissector_get_NAME); Dissector d; if ((d = find_dissector(name))) { @@ -48,8 +53,8 @@ WSLUA_CONSTRUCTOR Dissector_get (lua_State *L) { } /* Allow dissector key names to be sorted alphabetically. */ -static gint -compare_dissector_key_name(gconstpointer dissector_a, gconstpointer dissector_b) +static int +compare_dissector_key_name(const void *dissector_a, const void *dissector_b) { return strcmp((const char*)dissector_a, (const char*)dissector_b); } @@ -58,8 +63,6 @@ WSLUA_CONSTRUCTOR Dissector_list (lua_State *L) { /* Gets a Lua array table of all registered Dissector names. Note: This is an expensive operation, and should only be used for troubleshooting. - - @since 1.11.3 */ GList* list = get_dissector_names(); GList* elist = NULL; @@ -107,7 +110,7 @@ WSLUA_METHOD Dissector_call(lua_State* L) { are normal conditions and possibly don't need the Lua traceback. */ if (error) { WSLUA_ERROR(Dissector_call,error); } - lua_pushnumber(L,(lua_Number)len); + lua_pushinteger(L,(lua_Integer)len); WSLUA_RETURN(1); /* Number of bytes dissected. Note that some dissectors always return number of bytes in incoming buffer, so be aware. */ } @@ -166,15 +169,16 @@ WSLUA_CONSTRUCTOR DissectorTable_new (lua_State *L) { #define WSLUA_OPTARG_DissectorTable_new_UINAME 2 /* The name of the table in the user interface. Defaults to the name given in `tablename`, but can be any string. */ #define WSLUA_OPTARG_DissectorTable_new_TYPE 3 /* One of `ftypes.UINT8`, `ftypes.UINT16`, - `ftypes.UINT24`, `ftypes.UINT32`, or - `ftypes.STRING`. + `ftypes.UINT24`, `ftypes.UINT32`, + `ftypes.STRING`, `ftypes.NONE`, + or `ftypes.GUID`. Defaults to `ftypes.UINT32`. */ #define WSLUA_OPTARG_DissectorTable_new_BASE 4 /* One of `base.NONE`, `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX` or `base.HEX_DEC`. Defaults to `base.DEC`. */ #define WSLUA_OPTARG_DissectorTable_new_PROTO 5 /* The <<lua_class_Proto,`Proto`>> object that uses this dissector table. */ - const gchar* name = (const gchar*)luaL_checkstring(L,WSLUA_ARG_DissectorTable_new_TABLENAME); - const gchar* ui_name = (const gchar*)luaL_optstring(L,WSLUA_OPTARG_DissectorTable_new_UINAME,name); + const char* name = (const char*)luaL_checkstring(L,WSLUA_ARG_DissectorTable_new_TABLENAME); + const char* ui_name = (const char*)luaL_optstring(L,WSLUA_OPTARG_DissectorTable_new_UINAME,name); enum ftenum type = (enum ftenum)luaL_optinteger(L,WSLUA_OPTARG_DissectorTable_new_TYPE,FT_UINT32); unsigned base = (unsigned)luaL_optinteger(L,WSLUA_OPTARG_DissectorTable_new_BASE,BASE_DEC); DissectorTable dt; @@ -194,12 +198,16 @@ WSLUA_CONSTRUCTOR DissectorTable_new (lua_State *L) { case FT_UINT32: break; + case FT_GUID: + base = BASE_HEX; + break; + default: /* Calling WSLUA_OPTARG_ERROR raises a Lua error and returns from this function. */ WSLUA_OPTARG_ERROR( DissectorTable_new, TYPE, - "must be ftypes.UINT{8,16,24,32}, ftypes.STRING or ftypes.NONE"); + "must be ftypes.UINT{8,16,24,32}, ftypes.STRING, ftypes.GUID or ftypes.NONE"); break; } @@ -216,8 +224,8 @@ WSLUA_CONSTRUCTOR DissectorTable_new (lua_State *L) { dt->heur_list = NULL; dt->name = g_strdup(name); dt->ui_name = g_strdup(ui_name); - dt->created = TRUE; - dt->expired = FALSE; + dt->created = true; + dt->expired = false; lua_rawgeti(L, LUA_REGISTRYINDEX, dissectortable_table_ref); lua_pushstring(L, name); @@ -235,11 +243,23 @@ WSLUA_CONSTRUCTOR DissectorTable_heuristic_new(lua_State *L) { @since 4.2.0 */ #define WSLUA_ARG_DissectorTable_heuristic_new_TABLENAME 1 /* The short name of the table. Use lower-case alphanumeric, dot, and/or underscores. */ -#define WSLUA_ARG_DissectorTable_heuristic_new_PROTO 2 /* The <<lua_class_Proto,`Proto`>> object that uses this dissector table. */ - const gchar* name = (const gchar*)luaL_checkstring(L,WSLUA_ARG_DissectorTable_heuristic_new_TABLENAME); - Proto proto = checkProto(L, WSLUA_ARG_DissectorTable_heuristic_new_PROTO); +#define WSLUA_OPTARG_DissectorTable_heuristic_new_UINAME 2 /* The name of the table in the user interface. + Defaults to the name given in `tablename`, but can be any string. */ +#define WSLUA_ARG_DissectorTable_heuristic_new_PROTO 3 /* The <<lua_class_Proto,`Proto`>> object that uses this dissector table. */ + const char* name = (const char*)luaL_checkstring(L,WSLUA_ARG_DissectorTable_heuristic_new_TABLENAME); + const char* ui_name = NULL; + Proto proto = NULL; + int proto_id = -1; heur_dissector_list_t list; - int proto_id = proto_get_id_by_short_name(proto->name); + int idx = WSLUA_OPTARG_DissectorTable_heuristic_new_UINAME; + + if (lua_isstring(L, idx)) { + ui_name = luaL_checkstring(L, idx); + idx++; + } + + proto = checkProto(L, idx); + proto_id = proto_get_id_by_short_name(proto->name); list = find_heur_dissector_list(name); if (list) { @@ -247,14 +267,15 @@ WSLUA_CONSTRUCTOR DissectorTable_heuristic_new(lua_State *L) { return 0; } + DissectorTable dt; dt = (DissectorTable)g_malloc(sizeof(struct _wslua_distbl_t)); dt->table = NULL; - dt->heur_list = register_heur_dissector_list(name, proto_id); + dt->heur_list = register_heur_dissector_list_with_description(name, ui_name, proto_id); dt->name = g_strdup(name); - dt->ui_name = g_strdup(name); - dt->created = TRUE; - dt->expired = FALSE; + dt->ui_name = g_strdup(ui_name); + dt->created = true; + dt->expired = false; lua_rawgeti(L, LUA_REGISTRYINDEX, dissectortable_table_ref); lua_pushstring(L, name); @@ -282,7 +303,7 @@ typedef struct dissector_tables_foreach_table_info { /* this is the DATFunc_table function used for dissector_all_tables_foreach_table() so we can get all dissector_table names. This pushes the name into a table at stack index 1 */ static void -dissector_tables_list_func(const gchar *table_name, const gchar *ui_name _U_, gpointer user_data) { +dissector_tables_list_func(const char *table_name, const char *ui_name _U_, void *user_data) { dissector_tables_foreach_table_info_t *data = (dissector_tables_foreach_table_info_t*) user_data; lua_pushstring(data->L, table_name); lua_rawseti(data->L, 1, data->num); @@ -294,14 +315,12 @@ WSLUA_CONSTRUCTOR DissectorTable_list (lua_State *L) { use for the first argument to DissectorTable.get(). Note: This is an expensive operation, and should only be used for troubleshooting. - - @since 1.11.3 */ dissector_tables_foreach_table_info_t data = { 1, L }; lua_newtable(L); - dissector_all_tables_foreach_table(dissector_tables_list_func, (gpointer)&data, + dissector_all_tables_foreach_table(dissector_tables_list_func, (void *)&data, (GCompareFunc)compare_dissector_key_name); WSLUA_RETURN(1); /* The array table of registered DissectorTable names. */ @@ -310,7 +329,7 @@ WSLUA_CONSTRUCTOR DissectorTable_list (lua_State *L) { /* this is the DATFunc_heur_table function used for dissector_all_heur_tables_foreach_table() so we can get all heuristic dissector list names. This pushes the name into a table at stack index 1 */ static void -heur_dissector_tables_list_func(const gchar *table_name, struct heur_dissector_list *table _U_, gpointer user_data) { +heur_dissector_tables_list_func(const char *table_name, struct heur_dissector_list *table _U_, void *user_data) { dissector_tables_foreach_table_info_t *data = (dissector_tables_foreach_table_info_t*) user_data; lua_pushstring(data->L, table_name); lua_rawseti(data->L, 1, data->num); @@ -322,14 +341,12 @@ WSLUA_CONSTRUCTOR DissectorTable_heuristic_list (lua_State *L) { use for the first argument in Proto:register_heuristic(). Note: This is an expensive operation, and should only be used for troubleshooting. - - @since 1.11.3 */ dissector_tables_foreach_table_info_t data = { 1, L }; lua_newtable(L); - dissector_all_heur_tables_foreach_table(heur_dissector_tables_list_func, (gpointer)&data, NULL); + dissector_all_heur_tables_foreach_table(heur_dissector_tables_list_func, (void *)&data, NULL); WSLUA_RETURN(1); /* The array table of registered heuristic list names */ } @@ -343,7 +360,7 @@ WSLUA_CONSTRUCTOR DissectorTable_try_heuristics (lua_State *L) { #define WSLUA_ARG_DissectorTable_try_heuristics_PINFO 3 /* The packet info. */ #define WSLUA_ARG_DissectorTable_try_heuristics_TREE 4 /* The tree on which to add the protocol items. */ - const gchar* name = luaL_checkstring(L,WSLUA_ARG_DissectorTable_try_heuristics_LISTNAME); + const char* name = luaL_checkstring(L,WSLUA_ARG_DissectorTable_try_heuristics_LISTNAME); Tvb tvb = checkTvb(L,WSLUA_ARG_DissectorTable_try_heuristics_TVB); Pinfo pinfo = checkPinfo(L,WSLUA_ARG_DissectorTable_try_heuristics_PINFO); TreeItem tree = checkTreeItem(L,WSLUA_ARG_DissectorTable_try_heuristics_TREE); @@ -368,7 +385,7 @@ WSLUA_CONSTRUCTOR DissectorTable_get (lua_State *L) { Obtain a reference to an existing dissector table. */ #define WSLUA_ARG_DissectorTable_get_TABLENAME 1 /* The short name of the table. */ - const gchar* name = luaL_checkstring(L,WSLUA_ARG_DissectorTable_get_TABLENAME); + const char* name = luaL_checkstring(L,WSLUA_ARG_DissectorTable_get_TABLENAME); dissector_table_t table = find_dissector_table(name); if (table) { @@ -377,8 +394,8 @@ WSLUA_CONSTRUCTOR DissectorTable_get (lua_State *L) { dt->heur_list = NULL; dt->name = g_strdup(name); dt->ui_name = NULL; - dt->created = FALSE; - dt->expired = FALSE; + dt->created = false; + dt->expired = false; pushDissectorTable(L, dt); } else { @@ -422,18 +439,33 @@ WSLUA_METHOD DissectorTable_add (lua_State *L) { type = get_dissector_table_selector_type(dt->name); if (type == FT_STRING) { - gchar* pattern = g_strdup(luaL_checkstring(L,WSLUA_ARG_DissectorTable_add_PATTERN)); + char* pattern = g_strdup(luaL_checkstring(L,WSLUA_ARG_DissectorTable_add_PATTERN)); dissector_add_string(dt->name, pattern,handle); g_free (pattern); + } else if (type == FT_GUID) { + /* Handle GUID type (assuming it is represented as a string in Lua) */ + const char* guid_str = luaL_checkstring(L,WSLUA_ARG_DissectorTable_add_PATTERN); + fvalue_t* fval = fvalue_from_literal(type, guid_str, 0, NULL); + const e_guid_t* guid = fvalue_get_guid(fval); + guid_key gk = {*guid, 0}; + /* The dcerpc.uuid table requires its own initializer */ + if(strcmp(DCERPC_TABLE_NAME, dt->name) == 0) { + e_guid_t uuid; + memcpy(&uuid, guid, sizeof(e_guid_t)); + dcerpc_init_from_handle(dissector_handle_get_protocol_index(handle), &uuid, 0, handle); + } else { + dissector_add_guid(dt->name, &gk, handle); + guids_add_uuid(guid, dissector_handle_get_protocol_short_name(handle)); + } } else if ( type == FT_UINT32 || type == FT_UINT16 || type == FT_UINT8 || type == FT_UINT24 ) { if (lua_isnumber(L, WSLUA_ARG_DissectorTable_add_PATTERN)) { - guint32 port = wslua_checkguint32(L, WSLUA_ARG_DissectorTable_add_PATTERN); + uint32_t port = wslua_checkuint32(L, WSLUA_ARG_DissectorTable_add_PATTERN); dissector_add_uint(dt->name, port, handle); } else { /* Not a number, try as range */ - const gchar* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_add_PATTERN); + const char* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_add_PATTERN); range_t *range = NULL; - if (range_convert_str(NULL, &range, pattern, G_MAXUINT32) == CVT_NO_ERROR) { + if (range_convert_str(NULL, &range, pattern, UINT32_MAX) == CVT_NO_ERROR) { dissector_add_uint_range(dt->name, range, handle); } else { wmem_free (NULL, range); @@ -450,11 +482,7 @@ WSLUA_METHOD DissectorTable_add (lua_State *L) { } WSLUA_METHOD DissectorTable_set (lua_State *L) { - /* - Clear all existing dissectors from a table and add a new dissector or a range of new dissectors. - - @since 1.11.3 - */ + /* Clear all existing dissectors from a table and add a new dissector or a range of new dissectors. */ #define WSLUA_ARG_DissectorTable_set_PATTERN 2 /* The pattern to match (either an integer, a integer range or a string depending on the table's type). */ #define WSLUA_ARG_DissectorTable_set_DISSECTOR 3 /* The dissector to add (either a <<lua_class_Proto,`Proto`>> or a <<lua_class_Dissector,`Dissector`>>). */ @@ -484,19 +512,34 @@ WSLUA_METHOD DissectorTable_set (lua_State *L) { type = get_dissector_table_selector_type(dt->name); if (type == FT_STRING) { - const gchar* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_set_PATTERN); + const char* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_set_PATTERN); dissector_delete_all(dt->name, handle); dissector_add_string(dt->name, pattern,handle); + } else if (type == FT_GUID) { + /* Handle GUID type (assuming it is represented as a string in Lua) */ + const char* guid_str = luaL_checkstring(L,WSLUA_ARG_DissectorTable_set_PATTERN); + fvalue_t* fval = fvalue_from_literal(type, guid_str, 0, NULL); + const e_guid_t* guid = fvalue_get_guid(fval); + guid_key gk = {*guid, 0}; + /* The dcerpc.uuid table requires its own initializer */ + if(strcmp(DCERPC_TABLE_NAME, dt->name) == 0) { + e_guid_t uuid; + memcpy(&uuid, guid, sizeof(e_guid_t)); + dcerpc_init_from_handle(dissector_handle_get_protocol_index(handle), &uuid, 0, handle); + } else { + dissector_add_guid(dt->name, &gk, handle); + guids_add_uuid(guid, dissector_handle_get_protocol_short_name(handle)); + } } else if ( type == FT_UINT32 || type == FT_UINT16 || type == FT_UINT8 || type == FT_UINT24 ) { if (lua_isnumber(L, WSLUA_ARG_DissectorTable_set_PATTERN)) { - guint32 port = wslua_checkguint32(L, WSLUA_ARG_DissectorTable_set_PATTERN); + uint32_t port = wslua_checkuint32(L, WSLUA_ARG_DissectorTable_set_PATTERN); dissector_delete_all(dt->name, handle); dissector_add_uint(dt->name, port, handle); } else { /* Not a number, try as range */ - const gchar* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_set_PATTERN); + const char* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_set_PATTERN); range_t *range = NULL; - if (range_convert_str(NULL, &range, pattern, G_MAXUINT32) == CVT_NO_ERROR) { + if (range_convert_str(NULL, &range, pattern, UINT32_MAX) == CVT_NO_ERROR) { dissector_delete_all(dt->name, handle); dissector_add_uint_range(dt->name, range, handle); } else { @@ -540,18 +583,26 @@ WSLUA_METHOD DissectorTable_remove (lua_State *L) { type = get_dissector_table_selector_type(dt->name); if (type == FT_STRING) { - gchar* pattern = g_strdup(luaL_checkstring(L,WSLUA_ARG_DissectorTable_remove_PATTERN)); + char* pattern = g_strdup(luaL_checkstring(L,WSLUA_ARG_DissectorTable_remove_PATTERN)); dissector_delete_string(dt->name, pattern,handle); g_free (pattern); + } else if (type == FT_GUID) { + // Handle GUID type (assuming it is represented as a string in Lua) + const char* guid_str = luaL_checkstring(L,WSLUA_ARG_DissectorTable_remove_PATTERN); + fvalue_t* fval = fvalue_from_literal(type, guid_str, 0, NULL); + const e_guid_t* guid = fvalue_get_guid(fval); + guid_key gk = {*guid, 0}; + guids_delete_guid(guid); + dissector_delete_guid(dt->name, &gk, handle); } else if ( type == FT_UINT32 || type == FT_UINT16 || type == FT_UINT8 || type == FT_UINT24 ) { if (lua_isnumber(L, WSLUA_ARG_DissectorTable_remove_PATTERN)) { - guint32 port = wslua_checkguint32(L, WSLUA_ARG_DissectorTable_remove_PATTERN); + uint32_t port = wslua_checkuint32(L, WSLUA_ARG_DissectorTable_remove_PATTERN); dissector_delete_uint(dt->name, port, handle); } else { /* Not a number, try as range */ - const gchar* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_remove_PATTERN); + const char* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_remove_PATTERN); range_t *range = NULL; - if (range_convert_str(NULL, &range, pattern, G_MAXUINT32) == CVT_NO_ERROR) + if (range_convert_str(NULL, &range, pattern, UINT32_MAX) == CVT_NO_ERROR) dissector_delete_uint_range(dt->name, range, handle); else { wmem_free (NULL, range); @@ -566,11 +617,7 @@ WSLUA_METHOD DissectorTable_remove (lua_State *L) { } WSLUA_METHOD DissectorTable_remove_all (lua_State *L) { - /* - Remove all dissectors from a table. - - @since 1.11.3 - */ + /* Remove all dissectors from a table. */ #define WSLUA_ARG_DissectorTable_remove_all_DISSECTOR 2 /* The dissector to remove (either a <<lua_class_Proto,`Proto`>> or a <<lua_class_Dissector,`Dissector`>>). */ DissectorTable dt = checkDissectorTable(L,1); Dissector handle; @@ -607,8 +654,8 @@ WSLUA_METHOD DissectorTable_try (lua_State *L) { Pinfo pinfo = checkPinfo(L,WSLUA_ARG_DissectorTable_try_PINFO); TreeItem ti = checkTreeItem(L,WSLUA_ARG_DissectorTable_try_TREE); ftenum_t type; - gboolean handled = FALSE; - const gchar *volatile error = NULL; + bool handled = false; + const char *volatile error = NULL; int len = 0; if (! (dt && tvb && tvb->ws_tvb && pinfo && ti) ) return 0; @@ -618,18 +665,33 @@ WSLUA_METHOD DissectorTable_try (lua_State *L) { TRY { if (type == FT_STRING) { - const gchar* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_try_PATTERN); + const char* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_try_PATTERN); len = dissector_try_string(dt->table,pattern,tvb->ws_tvb,pinfo->ws_pinfo,ti->tree, NULL); if (len > 0) { - handled = TRUE; + handled = true; + } + } else if ( type == FT_GUID ) { + const char* guid_str = luaL_checkstring(L,WSLUA_ARG_DissectorTable_try_PATTERN); + fvalue_t* fval = fvalue_from_literal(type, guid_str, 0, NULL); + const e_guid_t* guid = fvalue_get_guid(fval); + guid_key gk = {*guid, 0}; + + len = dissector_try_guid(dt->table, &gk,tvb->ws_tvb,pinfo->ws_pinfo,ti->tree); + if (len > 0) { + handled = true; } } else if ( type == FT_UINT32 || type == FT_UINT16 || type == FT_UINT8 || type == FT_UINT24 ) { - guint32 port = wslua_checkguint32(L, WSLUA_ARG_DissectorTable_try_PATTERN); + uint32_t port = wslua_checkuint32(L, WSLUA_ARG_DissectorTable_try_PATTERN); len = dissector_try_uint(dt->table,port,tvb->ws_tvb,pinfo->ws_pinfo,ti->tree); if (len > 0) { - handled = TRUE; + handled = true; + } + } else if ( type == FT_NONE ) { + len = dissector_try_payload(dt->table,tvb->ws_tvb,pinfo->ws_pinfo,ti->tree); + if (len > 0) { + handled = true; } } else { error = "No such type of dissector table"; @@ -646,7 +708,7 @@ WSLUA_METHOD DissectorTable_try (lua_State *L) { if (error) { WSLUA_ERROR(DissectorTable_try,error); } - lua_pushnumber(L,(lua_Number)len); + lua_pushinteger(L,(lua_Integer)len); WSLUA_RETURN(1); /* Number of bytes dissected. Note that some dissectors always return number of bytes in incoming buffer, so be aware. */ } @@ -665,10 +727,16 @@ WSLUA_METHOD DissectorTable_get_dissector (lua_State *L) { type = get_dissector_table_selector_type(dt->name); if (type == FT_STRING) { - const gchar* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_get_dissector_PATTERN); + const char* pattern = luaL_checkstring(L,WSLUA_ARG_DissectorTable_get_dissector_PATTERN); handle = dissector_get_string_handle(dt->table,pattern); + } else if ( type == FT_GUID ) { + const char* guid_str = luaL_checkstring(L,WSLUA_ARG_DissectorTable_get_dissector_PATTERN); + fvalue_t* fval = fvalue_from_literal(type, guid_str, 0, NULL); + const e_guid_t* guid = fvalue_get_guid(fval); + guid_key gk = {*guid, 0}; + handle = dissector_get_guid_handle(dt->table,&gk); } else if ( type == FT_UINT32 || type == FT_UINT16 || type == FT_UINT8 || type == FT_UINT24 ) { - guint32 port = wslua_checkguint32(L, WSLUA_ARG_DissectorTable_get_dissector_PATTERN); + uint32_t port = wslua_checkuint32(L, WSLUA_ARG_DissectorTable_get_dissector_PATTERN); handle = dissector_get_uint_handle(dt->table,port); } @@ -685,8 +753,6 @@ WSLUA_METHOD DissectorTable_add_for_decode_as (lua_State *L) { /* Add the given <<lua_class_Proto,`Proto`>> to the “Decode as...” list for this DissectorTable. The passed-in <<lua_class_Proto,`Proto`>> object's `dissector()` function is used for dissecting. - - @since 1.99.1 */ #define WSLUA_ARG_DissectorTable_add_for_decode_as_PROTO 2 /* The <<lua_class_Proto,`Proto`>> to add. */ DissectorTable dt = checkDissectorTable(L,1); @@ -731,6 +797,11 @@ WSLUA_METAMETHOD DissectorTable__tostring(lua_State* L) { g_string_append_printf(s,"%s Integer(%i):\n",dt->name,base); break; } + case FT_GUID: + { + g_string_append_printf(s,"%s GUID:\n",dt->name); + break; + } case FT_NONE: { g_string_append_printf(s,"%s only for Decode As:\n",dt->name); @@ -751,7 +822,7 @@ static int DissectorTable__gc(lua_State* L) { if (dt->created && !dt->expired) { /* Created DissectorTable will pass GC two times */ - dt->expired = TRUE; + dt->expired = true; } else { g_free((char *)dt->name); g_free((char *)dt->ui_name); @@ -812,6 +883,7 @@ int wslua_deregister_dissector_tables(lua_State* L) { return 0; } + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/epan/wslua/wslua_dumper.c b/epan/wslua/wslua_dumper.c index de6b2aac..74f1f014 100644 --- a/epan/wslua/wslua_dumper.c +++ b/epan/wslua/wslua_dumper.c @@ -85,7 +85,7 @@ WSLUA_CONSTRUCTOR PseudoHeader_eth(lua_State* L) { PseudoHeader ph = (PseudoHeader)g_malloc(sizeof(struct lua_pseudo_header)); ph->type = PHDR_ETH; ph->wph = (union wtap_pseudo_header *)g_malloc(sizeof(union wtap_pseudo_header)); - ph->wph->eth.fcs_len = (gint)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_eth_FCSLEN,-1); + ph->wph->eth.fcs_len = (int)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_eth_FCSLEN,-1); pushPseudoHeader(L,ph); @@ -107,13 +107,13 @@ WSLUA_CONSTRUCTOR PseudoHeader_atm(lua_State* L) { PseudoHeader ph = (PseudoHeader)g_malloc(sizeof(struct lua_pseudo_header)); ph->type = PHDR_ATM; ph->wph = (union wtap_pseudo_header *)g_malloc(sizeof(union wtap_pseudo_header)); - ph->wph->atm.aal = (guint8)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_AAL,5); - ph->wph->atm.vpi = (guint16)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_VPI,1); - ph->wph->atm.vci = (guint16)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_VCI,1); - ph->wph->atm.channel = (guint16)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_CHANNEL,0); - ph->wph->atm.cells = (guint16)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_CELLS,1); - ph->wph->atm.aal5t_u2u = (guint16)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_AAL5U2U,1); - ph->wph->atm.aal5t_len = (guint16)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_AAL5LEN,0); + ph->wph->atm.aal = (uint8_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_AAL,5); + ph->wph->atm.vpi = (uint16_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_VPI,1); + ph->wph->atm.vci = (uint16_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_VCI,1); + ph->wph->atm.channel = (uint16_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_CHANNEL,0); + ph->wph->atm.cells = (uint16_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_CELLS,1); + ph->wph->atm.aal5t_u2u = (uint16_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_AAL5U2U,1); + ph->wph->atm.aal5t_len = (uint16_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_atm_AAL5LEN,0); pushPseudoHeader(L,ph); WSLUA_RETURN(1); @@ -128,9 +128,9 @@ WSLUA_CONSTRUCTOR PseudoHeader_mtp2(lua_State* L) { PseudoHeader ph = (PseudoHeader)g_malloc(sizeof(struct lua_pseudo_header)); ph->type = PHDR_MTP2; ph->wph = (union wtap_pseudo_header *)g_malloc(sizeof(union wtap_pseudo_header)); - ph->wph->mtp2.sent = (guint8)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_mtp2_SENT,0); - ph->wph->mtp2.annex_a_used = (guint8)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_mtp2_ANNEXA,0); - ph->wph->mtp2.link_number = (guint16)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_mtp2_LINKNUM,0); + ph->wph->mtp2.sent = (uint8_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_mtp2_SENT,0); + ph->wph->mtp2.annex_a_used = (uint8_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_mtp2_ANNEXA,0); + ph->wph->mtp2.link_number = (uint16_t)luaL_optinteger(L,WSLUA_OPTARG_PseudoHeader_mtp2_LINKNUM,0); pushPseudoHeader(L,ph); WSLUA_RETURN(1); /* The MTP2 pseudoheader */ @@ -173,7 +173,7 @@ int PseudoHeader_register(lua_State* L) { WSLUA_CLASS_DEFINE(Dumper,FAIL_ON_NULL("Dumper already closed")); -static GHashTable* dumper_encaps = NULL; +static GHashTable* dumper_encaps; #define DUMPER_ENCAP(d) GPOINTER_TO_INT(g_hash_table_lookup(dumper_encaps,d)) static const char* cross_plat_fname(const char* fname) { @@ -199,26 +199,39 @@ static const char* cross_plat_fname(const char* fname) { WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) { /* Creates a file to write packets. - `Dumper:new_for_current()` will probably be a better choice. + `Dumper:new_for_current()` will probably be a better choice, especially for file types other than pcapng. */ #define WSLUA_ARG_Dumper_new_FILENAME 1 /* The name of the capture file to be created. */ -#define WSLUA_OPTARG_Dumper_new_FILETYPE 2 /* The type of the file to be created - a number returned by `wtap_name_to_file_type_subtype()`. +#define WSLUA_OPTARG_Dumper_new_FILETYPE 2 /* The type of the file to be created - a number returned by `wtap_name_to_file_type_subtype()`. Defaults to pcapng. (The `wtap_filetypes` table is deprecated, and should only be used - in code that must run on Wireshark 3.4.3 and earlier 3.4 releases + in code that must run on Wireshark 3.4.3 and earlier 3.4.x releases or in Wireshark 3.2.11 and earlier 3.2.x releases.) */ -#define WSLUA_OPTARG_Dumper_new_ENCAP 3 /* The encapsulation to be used in the file to be created - a number entry from the `wtap_encaps` table. */ +#define WSLUA_OPTARG_Dumper_new_ENCAP 3 /* The encapsulation to be used in the file to be created - a number entry from the `wtap_encaps` table. + Defaults to per-packet encapsulation for pcapng + (which doesn't have file-level encapsulation; + this will create IDBs on demand as necessary) + and Ethernet encapsulation for other file types. */ Dumper d; const char* fname = luaL_checkstring(L,WSLUA_ARG_Dumper_new_FILENAME); - int filetype = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_FILETYPE,wtap_pcap_file_type_subtype()); - int encap = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_ENCAP,WTAP_ENCAP_ETHERNET); + int filetype = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_FILETYPE,wtap_pcapng_file_type_subtype()); + /* If we're writing pcapng, then WTAP_ENCAP_NONE and WTAP_ENCAP_PER_PACKET + * generate a fake IDB on demand when the first packet for an encapsulation + * type is written. Specifying any other encapsulation will generate a fake + * IDB for that encapsulation upon opening even if there are no packets of + * that type. + * XXX - Default to PER_PACKET for any file type that supports it? */ + int encap = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_ENCAP, filetype == wtap_pcapng_file_type_subtype() ? WTAP_ENCAP_PER_PACKET : WTAP_ENCAP_ETHERNET); int err = 0; - gchar *err_info = NULL; + char *err_info = NULL; const char* filename = cross_plat_fname(fname); wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; params.encap = encap; + /* XXX - Check for an existing file, or the same file name as the current + * capture file? + */ d = wtap_dump_open(filename, filetype, WTAP_UNCOMPRESSED, ¶ms, &err, &err_info); @@ -293,7 +306,7 @@ WSLUA_METHOD Dumper_close(lua_State* L) { /* Closes a dumper. */ Dumper* dp = (Dumper*)luaL_checkudata(L, 1, "Dumper"); int err; - gchar *err_info; + char *err_info; if (! *dp) { WSLUA_ERROR(Dumper_close,"Cannot operate on a closed dumper"); @@ -351,7 +364,7 @@ WSLUA_METHOD Dumper_dump(lua_State* L) { wtap_rec rec; double ts; int err; - gchar *err_info; + char *err_info; if (!d) return 0; @@ -412,13 +425,13 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) { /* Creates a capture file using the same encapsulation as the one of the current packet. */ -#define WSLUA_OPTARG_Dumper_new_for_current_FILETYPE 2 /* The file type. Defaults to pcap. */ +#define WSLUA_OPTARG_Dumper_new_for_current_FILETYPE 2 /* The file type. Defaults to pcapng. */ Dumper d; const char* fname = luaL_checkstring(L,1); - int filetype = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_for_current_FILETYPE,wtap_pcap_file_type_subtype()); + int filetype = (int)luaL_optinteger(L,WSLUA_OPTARG_Dumper_new_for_current_FILETYPE,wtap_pcapng_file_type_subtype()); int encap; int err = 0; - gchar *err_info = NULL; + char *err_info = NULL; const char* filename = cross_plat_fname(fname); wtap_dump_params params = WTAP_DUMP_PARAMS_INIT; @@ -506,11 +519,11 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) { */ Dumper d = checkDumper(L,1); wtap_rec rec; - const guchar* data; + const unsigned char* data; tvbuff_t* tvb; struct data_source *data_src; int err = 0; - gchar *err_info; + char *err_info; if (!d) return 0; @@ -546,12 +559,12 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) { */ if (lua_pinfo->fd->has_modified_block) { rec.block = epan_get_modified_block(lua_pinfo->epan, lua_pinfo->fd); - rec.block_was_modified = TRUE; + rec.block_was_modified = true; } else { rec.block = lua_pinfo->rec->block; } - data = (const guchar *)tvb_memdup(lua_pinfo->pool,tvb,0,rec.rec_header.packet_header.caplen); + data = (const unsigned char *)tvb_memdup(lua_pinfo->pool,tvb,0,rec.rec_header.packet_header.caplen); if (! wtap_dump(d, &rec, data, &err, &err_info)) { switch (err) { @@ -576,7 +589,7 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) { static int Dumper__gc(lua_State* L) { Dumper* dp = (Dumper*)luaL_checkudata(L, 1, "Dumper"); int err; - gchar *err_info; + char *err_info; /* If we are Garbage Collected it means the Dumper is no longer usable. Close it */ @@ -615,6 +628,9 @@ WSLUA_META Dumper_meta[] = { }; int Dumper_register(lua_State* L) { + if (dumper_encaps != NULL) { + g_hash_table_unref(dumper_encaps); + } dumper_encaps = g_hash_table_new(g_direct_hash,g_direct_equal); WSLUA_REGISTER_CLASS(Dumper); return 0; diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c index 17db1974..72ef6f0b 100644 --- a/epan/wslua/wslua_field.c +++ b/epan/wslua/wslua_field.c @@ -31,17 +31,17 @@ WSLUA_CLASS_DEFINE(FieldInfo,FAIL_ON_NULL_OR_EXPIRED("FieldInfo")); or `Field()` before-hand, or it can be called on new fields created by Lua from a `ProtoField`. */ -static GPtrArray* outstanding_FieldInfo = NULL; +static GPtrArray* outstanding_FieldInfo; FieldInfo* push_FieldInfo(lua_State* L, field_info* f) { FieldInfo fi = (FieldInfo) g_malloc(sizeof(struct _wslua_field_info)); fi->ws_fi = f; - fi->expired = FALSE; + fi->expired = false; g_ptr_array_add(outstanding_FieldInfo,fi); return pushFieldInfo(L,fi); } -CLEAR_OUTSTANDING(FieldInfo,expired,TRUE) +CLEAR_OUTSTANDING(FieldInfo,expired,true) /* WSLUA_ATTRIBUTE FieldInfo_len RO The length of this field. */ WSLUA_METAMETHOD FieldInfo__len(lua_State* L) { @@ -50,7 +50,7 @@ WSLUA_METAMETHOD FieldInfo__len(lua_State* L) { */ FieldInfo fi = checkFieldInfo(L,1); - lua_pushnumber(L,fi->ws_fi->length); + lua_pushinteger(L,fi->ws_fi->length); return 1; } @@ -61,7 +61,7 @@ WSLUA_METAMETHOD FieldInfo__unm(lua_State* L) { */ FieldInfo fi = checkFieldInfo(L,1); - lua_pushnumber(L,fi->ws_fi->start); + lua_pushinteger(L,fi->ws_fi->start); return 1; } @@ -91,13 +91,13 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) { case FT_UINT24: case FT_UINT32: case FT_FRAMENUM: - lua_pushnumber(L,(lua_Number)(fvalue_get_uinteger(fi->ws_fi->value))); + lua_pushinteger(L,(lua_Integer)(fvalue_get_uinteger(fi->ws_fi->value))); return 1; case FT_INT8: case FT_INT16: case FT_INT24: case FT_INT32: - lua_pushnumber(L,(lua_Number)(fvalue_get_sinteger(fi->ws_fi->value))); + lua_pushinteger(L,(lua_Integer)(fvalue_get_sinteger(fi->ws_fi->value))); return 1; case FT_FLOAT: case FT_DOUBLE: @@ -151,7 +151,7 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) { case FT_STRING: case FT_STRINGZ: case FT_STRINGZPAD: { - gchar* repr = fvalue_to_string_repr(NULL, fi->ws_fi->value, FTREPR_DISPLAY, BASE_NONE); + char* repr = fvalue_to_string_repr(NULL, fi->ws_fi->value, FTREPR_DISPLAY, BASE_NONE); if (repr) { lua_pushstring(L, repr); @@ -179,7 +179,7 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) { { ByteArray ba = g_byte_array_new(); g_byte_array_append(ba, fvalue_get_bytes_data(fi->ws_fi->value), - (guint)fvalue_length2(fi->ws_fi->value)); + (unsigned)fvalue_length2(fi->ws_fi->value)); pushByteArray(L,ba); return 1; } @@ -187,9 +187,9 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) { { ByteArray ba = g_byte_array_new(); tvbuff_t* tvb = fvalue_get_protocol(fi->ws_fi->value); - guint8* raw; + uint8_t* raw; if (tvb != NULL) { - raw = (guint8 *)tvb_memdup(NULL, tvb, 0, tvb_captured_length(tvb)); + raw = (uint8_t *)tvb_memdup(NULL, tvb, 0, tvb_captured_length(tvb)); g_byte_array_append(ba, raw, tvb_captured_length(tvb)); wmem_free(NULL, raw); } @@ -210,7 +210,7 @@ WSLUA_METAMETHOD FieldInfo__tostring(lua_State* L) { /* The string representation of the field. */ FieldInfo fi = checkFieldInfo(L,1); - gchar* repr = NULL; + char* repr = NULL; if (fi->ws_fi->hfinfo->type == FT_PROTOCOL) { repr = fvalue_to_string_repr(NULL, fi->ws_fi->value,FTREPR_DFILTER,BASE_NONE); @@ -235,9 +235,9 @@ WSLUA_METAMETHOD FieldInfo__tostring(lua_State* L) { static int FieldInfo_get_display(lua_State* L) { /* The display string of this field as seen in GUI. */ FieldInfo fi = checkFieldInfo(L,1); - gchar label_str[ITEM_LABEL_LENGTH+1]; - gchar *label_ptr; - gchar *value_ptr; + char label_str[ITEM_LABEL_LENGTH+1]; + char *label_ptr; + char *value_ptr; if (!fi->ws_fi->rep) { label_ptr = label_str; @@ -261,14 +261,12 @@ static int FieldInfo_get_display(lua_State* L) { /* WSLUA_ATTRIBUTE FieldInfo_type RO The internal field type, a number which matches one of the `ftype` values. - - @since 1.99.8 */ static int FieldInfo_get_type(lua_State* L) { FieldInfo fi = checkFieldInfo(L,1); if (fi->ws_fi->hfinfo) { - lua_pushnumber(L, fi->ws_fi->hfinfo->type); + lua_pushinteger(L, fi->ws_fi->hfinfo->type); } else { lua_pushnil(L); @@ -279,8 +277,6 @@ static int FieldInfo_get_type(lua_State* L) { /* WSLUA_ATTRIBUTE FieldInfo_source RO The source `Tvb` object the `FieldInfo` is derived from, or nil if there is none. - - @since 1.99.8 */ static int FieldInfo_get_source(lua_State* L) { FieldInfo fi = checkFieldInfo(L,1); @@ -320,10 +316,7 @@ static int FieldInfo_get_generated(lua_State* L) { return 1; } -/* WSLUA_ATTRIBUTE FieldInfo_hidden RO Whether this field was marked as hidden (boolean). - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE FieldInfo_hidden RO Whether this field was marked as hidden (boolean). */ static int FieldInfo_get_hidden(lua_State* L) { FieldInfo fi = checkFieldInfo(L,1); @@ -331,10 +324,7 @@ static int FieldInfo_get_hidden(lua_State* L) { return 1; } -/* WSLUA_ATTRIBUTE FieldInfo_is_url RO Whether this field was marked as being a URL (boolean). - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE FieldInfo_is_url RO Whether this field was marked as being a URL (boolean). */ static int FieldInfo_get_is_url(lua_State* L) { FieldInfo fi = checkFieldInfo(L,1); @@ -342,10 +332,7 @@ static int FieldInfo_get_is_url(lua_State* L) { return 1; } -/* WSLUA_ATTRIBUTE FieldInfo_little_endian RO Whether this field is little-endian encoded (boolean). - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE FieldInfo_little_endian RO Whether this field is little-endian encoded (boolean). */ static int FieldInfo_get_little_endian(lua_State* L) { FieldInfo fi = checkFieldInfo(L,1); @@ -353,10 +340,7 @@ static int FieldInfo_get_little_endian(lua_State* L) { return 1; } -/* WSLUA_ATTRIBUTE FieldInfo_big_endian RO Whether this field is big-endian encoded (boolean). - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE FieldInfo_big_endian RO Whether this field is big-endian encoded (boolean). */ static int FieldInfo_get_big_endian(lua_State* L) { FieldInfo fi = checkFieldInfo(L,1); @@ -364,10 +348,7 @@ static int FieldInfo_get_big_endian(lua_State* L) { return 1; } -/* WSLUA_ATTRIBUTE FieldInfo_name RO The filter name of this field. - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE FieldInfo_name RO The filter name of this field. */ static int FieldInfo_get_name(lua_State* L) { /* The filter name of this field. */ FieldInfo fi = checkFieldInfo(L,1); @@ -433,7 +414,7 @@ static int FieldInfo__gc(lua_State* L) { if (!fi) return 0; if (!fi->expired) - fi->expired = TRUE; + fi->expired = true; else /* do NOT free fi->ws_fi */ g_free(fi); @@ -490,7 +471,7 @@ WSLUA_FUNCTION wslua_all_field_infos(lua_State* L) { */ GPtrArray* found; int items_found = 0; - guint i; + unsigned i; if (! lua_tree || ! lua_tree->tree ) { WSLUA_ERROR(wslua_all_field_infos,"Cannot be called outside a listener or dissector"); @@ -505,7 +486,7 @@ WSLUA_FUNCTION wslua_all_field_infos(lua_State* L) { items_found++; } - g_ptr_array_free(found,TRUE); + g_ptr_array_free(found,true); } return items_found; @@ -520,8 +501,8 @@ WSLUA_CLASS_DEFINE(Field,FAIL_ON_NULL("Field")); */ /* Array of Field (struct _wslua_header_field_info*) pointers.*/ -static GPtrArray* wanted_fields = NULL; -static dfilter_t* wslua_dfilter = NULL; +static GPtrArray* wanted_fields; +static dfilter_t* wslua_dfilter; /* We use a fake dfilter for Lua field extractors, so that * epan_dissect_run() will populate the fields. This won't happen @@ -537,7 +518,7 @@ void wslua_prime_dfilter(epan_dissect_t *edt) { } /* Check if we have any registered field extractors. */ -gboolean wslua_has_field_extractors(void) { +bool wslua_has_field_extractors(void) { return (wslua_dfilter && dfilter_has_interesting_fields(wslua_dfilter)); } @@ -552,10 +533,10 @@ gboolean wslua_has_field_extractors(void) { * after the fields are primed. */ -static gboolean fake_tap = FALSE; +static bool fake_tap; void lua_prime_all_fields(proto_tree* tree _U_) { GString* fake_tap_filter = g_string_new("frame"); - guint i; + unsigned i; df_error_t *df_err; for(i=0; i < wanted_fields->len; i++) { @@ -568,10 +549,10 @@ void lua_prime_all_fields(proto_tree* tree _U_) { } g_string_append_printf(fake_tap_filter, " || %s", f->hfi->abbrev); - fake_tap = TRUE; + fake_tap = true; } - g_ptr_array_free(wanted_fields,TRUE); + g_ptr_array_free(wanted_fields,true); wanted_fields = NULL; if (fake_tap && fake_tap_filter->len > strlen("frame")) { @@ -598,7 +579,7 @@ WSLUA_CONSTRUCTOR Field_new(lua_State *L) { Create a Field extractor. */ #define WSLUA_ARG_Field_new_FIELDNAME 1 /* The filter name of the field (e.g. ip.addr) */ - const gchar* name = luaL_checkstring(L,WSLUA_ARG_Field_new_FIELDNAME); + const char* name = luaL_checkstring(L,WSLUA_ARG_Field_new_FIELDNAME); Field f; if (!proto_registrar_get_byname(name) && !wslua_is_field_available(L, name)) { @@ -624,8 +605,6 @@ WSLUA_CONSTRUCTOR Field_list(lua_State *L) { /* Gets a Lua array table of all registered field filter names. NOTE: This is an expensive operation, and should only be used for troubleshooting. - - @since 1.11.3 */ void *cookie, *cookie2; int i = -1; @@ -676,10 +655,7 @@ WSLUA_CONSTRUCTOR Field_list(lua_State *L) { lua_pushnil(L) -/* WSLUA_ATTRIBUTE Field_name RO The filter name of this field, or nil. - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE Field_name RO The filter name of this field, or nil. */ static int Field_get_name(lua_State* L) { Field f = checkField(L,1); header_field_info* hfinfo = NULL; @@ -689,10 +665,7 @@ static int Field_get_name(lua_State* L) { return 1; } -/* WSLUA_ATTRIBUTE Field_display RO The full display name of this field, or nil. - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE Field_display RO The full display name of this field, or nil. */ static int Field_get_display(lua_State* L) { Field f = checkField(L,1); header_field_info* hfinfo = NULL; @@ -702,15 +675,12 @@ static int Field_get_display(lua_State* L) { return 1; } -/* WSLUA_ATTRIBUTE Field_type RO The `ftype` of this field, or nil. - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE Field_type RO The `ftype` of this field, or nil. */ static int Field_get_type(lua_State* L) { Field f = checkField(L,1); header_field_info* hfinfo = NULL; - GET_HFINFO_MEMBER(lua_pushnumber, type); + GET_HFINFO_MEMBER(lua_pushinteger, type); return 1; } @@ -733,7 +703,7 @@ WSLUA_METAMETHOD Field__call (lua_State* L) { while (in) { GPtrArray* found = proto_get_finfo_ptr_array(lua_tree->tree, in->id); - guint i; + unsigned i; if (found) { for (i=0; i<found->len; i++) { push_FieldInfo(L, (field_info *) g_ptr_array_index(found,i)); @@ -796,9 +766,15 @@ WSLUA_META Field_meta[] = { int Field_register(lua_State* L) { + if (wanted_fields != NULL) { + g_ptr_array_unref(wanted_fields); + } wanted_fields = g_ptr_array_new(); WSLUA_REGISTER_CLASS_WITH_ATTRS(Field); + if (outstanding_FieldInfo != NULL) { + g_ptr_array_unref(outstanding_FieldInfo); + } outstanding_FieldInfo = g_ptr_array_new(); return 0; @@ -812,7 +788,7 @@ int wslua_deregister_fields(lua_State* L _U_) { if (fake_tap) { remove_tap_listener(&fake_tap); - fake_tap = FALSE; + fake_tap = false; } return 0; diff --git a/epan/wslua/wslua_file.c b/epan/wslua/wslua_file.c index d9f1ff99..80117088 100644 --- a/epan/wslua/wslua_file.c +++ b/epan/wslua/wslua_file.c @@ -13,6 +13,7 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "config.h" +#define WS_LOG_DOMAIN LOG_DOMAIN_WSLUA #include "wslua_file_common.h" @@ -25,8 +26,6 @@ The classes/functions defined in this section allow you to create your own custom Lua-based "capture" file reader, or writer, or both. - - @since 1.11.3 */ @@ -77,8 +76,6 @@ WSLUA_CLASS_DEFINE(File,FAIL_ON_NULL_OR_EXPIRED("File")); return false end ---- - - @since 1.11.3 */ @@ -91,7 +88,7 @@ File* push_File(lua_State* L, FILE_T ft) { File f = (File) g_malloc(sizeof(struct _wslua_file)); f->file = ft; f->wdh = NULL; - f->expired = FALSE; + f->expired = false; return pushFile(L,f); } @@ -99,11 +96,11 @@ File* push_Wdh(lua_State* L, wtap_dumper *wdh) { File f = (File) g_malloc(sizeof(struct _wslua_file)); f->file = (FILE_T)wdh->fh; f->wdh = wdh; - f->expired = FALSE; + f->expired = false; return pushFile(L,f); } -static gboolean file_is_reader(File f) { +static bool file_is_reader(File f) { return (f->wdh == NULL); } @@ -116,15 +113,15 @@ static gboolean file_is_reader(File f) { #define WSLUA_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ static int File_read_number (lua_State *L, FILE_T ft) { lua_Number d; - gchar buff[WSLUA_MAXNUMBER2STR]; + char buff[WSLUA_MAXNUMBER2STR]; int buff_end = 0; int c = -1; int num_digits = 0; - gboolean has_decimal = FALSE; + bool has_decimal = false; c = file_peekc(ft); if (c == '+' || c == '-') { - buff[buff_end++] = (gchar)c; + buff[buff_end++] = (char)c; /* make sure next char is a digit */ c = file_peekc(ft); if (c < '0' || c > '9') { @@ -137,13 +134,13 @@ static int File_read_number (lua_State *L, FILE_T ft) { while((c = file_peekc(ft)) > 0 && buff_end < (WSLUA_MAXNUMBER2STR-1)) { if (c >= '0' && c <= '9') { - buff[buff_end++] = (gchar)c; + buff[buff_end++] = (char)c; num_digits++; file_getc(ft); } else if (!has_decimal && c == '.') { - has_decimal = TRUE; - buff[buff_end++] = (gchar)c; + has_decimal = true; + buff[buff_end++] = (char)c; file_getc(ft); } else break; @@ -166,9 +163,9 @@ static int File_read_number (lua_State *L, FILE_T ft) { * the stack (or nil on EOF). */ static int File_read_line(lua_State *L, FILE_T ft) { - static gchar linebuff[MAX_LINE_LENGTH]; - gint64 pos_before = file_tell(ft); - gint length = 0; + static char linebuff[MAX_LINE_LENGTH]; + int64_t pos_before = file_tell(ft); + int length = 0; if (file_gets(linebuff, MAX_LINE_LENGTH, ft) == NULL) { /* No characters found, or error */ @@ -179,7 +176,7 @@ static int File_read_line(lua_State *L, FILE_T ft) { } /* Set length (avoiding strlen()) */ - length = (gint)(file_tell(ft) - pos_before); + length = (int)(file_tell(ft) - pos_before); /* ...but don't want to include newline in line length */ if (length > 0 && linebuff[length-1] == '\n') { @@ -203,11 +200,6 @@ static int File_read_line(lua_State *L, FILE_T ft) { */ #define WSLUA_BUFFERSIZE 1024 -/* Lua 5.1 used lua_objlen() instead of lua_rawlen() */ -#if LUA_VERSION_NUM == 501 -#define lua_rawlen lua_objlen -#endif - /** * Reads some data and returns the number of bytes read. * The actual data (possibly an empty string) is pushed on the Lua stack. @@ -216,7 +208,7 @@ static int File_read_chars(lua_State *L, FILE_T ft, size_t n) { size_t rlen; /* how much to read */ size_t nr; /* number of chars actually read */ int nri; /* temp number of chars read, as an int to handle -1 errors */ - gchar buff[WSLUA_BUFFERSIZE]; /* for file_read to write to, and we push into Lua */ + char buff[WSLUA_BUFFERSIZE]; /* for file_read to write to, and we push into Lua */ luaL_Buffer b; rlen = WSLUA_BUFFERSIZE; /* try to read that much each time */ @@ -339,9 +331,9 @@ WSLUA_METHOD File_seek(lua_State* L) { File f = checkFile(L,1); int op = luaL_checkoption(L, 2, "cur", modenames); #if LUA_VERSION_NUM >= 503 - gint64 offset = (gint64)luaL_optinteger(L, 3, 0); + int64_t offset = (int64_t)luaL_optinteger(L, 3, 0); #else - gint64 offset = (gint64) luaL_optlong(L, 3, 0); + int64_t offset = (int64_t) luaL_optlong(L, 3, 0); #endif int err; @@ -355,7 +347,7 @@ WSLUA_METHOD File_seek(lua_State* L) { return 2; } - lua_pushnumber(L, (lua_Number)(file_tell(f->file))); + lua_pushinteger(L, (lua_Integer)(file_tell(f->file))); } else { offset = wtap_dump_file_seek(f->wdh, offset, mode[op], &err); @@ -374,7 +366,7 @@ WSLUA_METHOD File_seek(lua_State* L) { return 2; } - lua_pushnumber(L, (lua_Number)(offset)); + lua_pushinteger(L, (lua_Integer)(offset)); } WSLUA_RETURN(1); /* The current file cursor position as a number. */ @@ -422,7 +414,7 @@ WSLUA_METHOD File_write(lua_State* L) { File f = checkFile(L,1); int arg = 2; /* beginning index for arguments */ int nargs = lua_gettop(L) - 1; - int status = TRUE; + int status = true; int err = 0; if (!f->wdh) { diff --git a/epan/wslua/wslua_file_common.h b/epan/wslua/wslua_file_common.h index 6ff98b65..ac221460 100644 --- a/epan/wslua/wslua_file_common.h +++ b/epan/wslua/wslua_file_common.h @@ -50,12 +50,12 @@ extern int set_wdh_priv_table_ref(lua_State* L, wtap_dumper *wdh); extern void remove_wdh_priv(lua_State* L, wtap_dumper *wdh); /* implemented in other c files than wslua_file_common.c */ -extern CaptureInfo* push_CaptureInfo(lua_State* L, wtap *wth, const gboolean first_time); +extern CaptureInfo* push_CaptureInfo(lua_State* L, wtap *wth, const bool first_time); extern CaptureInfoConst* push_CaptureInfoConst(lua_State* L, wtap_dumper *wdh); extern File* push_File(lua_State* L, FILE_T ft); extern File* push_Wdh(lua_State* L, wtap_dumper *wdh); extern FrameInfo* push_FrameInfo(lua_State* L, wtap_rec *rec, Buffer* buf); -extern FrameInfoConst* push_FrameInfoConst(lua_State* L, const wtap_rec *rec, const guint8 *pd); +extern FrameInfoConst* push_FrameInfoConst(lua_State* L, const wtap_rec *rec, const uint8_t *pd); /* diff --git a/epan/wslua/wslua_file_handler.c b/epan/wslua/wslua_file_handler.c index f0c9ad83..5807e88c 100644 --- a/epan/wslua/wslua_file_handler.c +++ b/epan/wslua/wslua_file_handler.c @@ -13,6 +13,7 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "config.h" +#define WS_LOG_DOMAIN LOG_DOMAIN_WSLUA #include "wslua_file_common.h" @@ -27,19 +28,17 @@ WSLUA_CLASS_DEFINE(FileHandler,NOP); A FileHandler object, created by a call to FileHandler.new(arg1, arg2, ...). The FileHandler object lets you create a file-format reader, or writer, or both, by setting your own read_open/read or write_open/write functions. - - @since 1.11.3 */ static int filehandler_cb_error_handler(lua_State* L) { - const gchar* error = lua_tostring(L,1); - const gchar* functype = luaL_optstring(L, lua_upvalueindex(1), "UNKNOWN"); + const char* error = lua_tostring(L,1); + const char* functype = luaL_optstring(L, lua_upvalueindex(1), "UNKNOWN"); report_failure("Lua: Error During execution of FileHandler %s callback:\n %s",functype,error); lua_pop(L, 1); return 0; } -static int push_error_handler(lua_State* L, const gchar* funcname) { +static int push_error_handler(lua_State* L, const char* funcname) { lua_pushstring(L, funcname); lua_pushcclosure(L, filehandler_cb_error_handler, 1); return 1; @@ -52,13 +51,13 @@ static GSList *registered_file_handlers; /* During file routines, we cannot allow the FileHandler to get deregistered, since that would change the GArray's in file_access.c and hilarity would ensue. So we set this to true right before pcall(), and back to false afterwards */ -static gboolean in_routine = FALSE; +static bool in_routine; static void -report_error(int *err, gchar **err_info, const char *fmt, ...) +report_error(int *err, char **err_info, const char *fmt, ...) { va_list ap; - gchar *msg; + char *msg; va_start(ap, fmt); msg = ws_strdup_vprintf(fmt, ap); @@ -102,11 +101,11 @@ report_error(int *err, gchar **err_info, const char *fmt, ...) return retval; \ } \ /* now guard against deregistering during pcall() */ \ - in_routine = TRUE + in_routine = true #define END_FILEHANDLER_ROUTINE() \ /* now allow deregistering again */ \ - in_routine = FALSE + in_routine = false /* LUA_ERRGCMM is in Lua 5.2 only - making it 9 disables it */ @@ -132,12 +131,12 @@ report_error(int *err, gchar **err_info, const char *fmt, ...) break; /* some declarations */ -static gboolean +static bool wslua_filehandler_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *offset); -static gboolean -wslua_filehandler_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info); + int *err, char **err_info, int64_t *offset); +static bool +wslua_filehandler_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, + int *err, char **err_info); static void wslua_filehandler_close(wtap *wth); static void @@ -156,7 +155,7 @@ wslua_filehandler_sequential_close(wtap *wth); * field in the "struct wtap" to the type of the file. */ static wtap_open_return_val -wslua_filehandler_open(wtap *wth, int *err, gchar **err_info) +wslua_filehandler_open(wtap *wth, int *err, char **err_info) { FileHandler fh = (FileHandler)(wth->wslua_data); wtap_open_return_val retval = WTAP_OPEN_NOT_MINE; @@ -169,7 +168,7 @@ wslua_filehandler_open(wtap *wth, int *err, gchar **err_info) create_wth_priv(L, wth); fp = push_File(L, wth->fh); - fc = push_CaptureInfo(L, wth, TRUE); + fc = push_CaptureInfo(L, wth, true); errno = WTAP_ERR_CANT_OPEN; switch ( lua_pcall(L,2,1,1) ) { @@ -181,8 +180,8 @@ wslua_filehandler_open(wtap *wth, int *err, gchar **err_info) END_FILEHANDLER_ROUTINE(); - (*fp)->expired = TRUE; - (*fc)->expired = TRUE; + (*fp)->expired = true; + (*fc)->expired = true; if (retval == WTAP_OPEN_MINE) { /* this is our file type - set the routines and settings into wtap */ @@ -235,9 +234,9 @@ wslua_filehandler_open(wtap *wth, int *err, gchar **err_info) return retval; } -static gboolean +static bool wslua_filehandler_read_packet(wtap *wth, FILE_T wth_fh, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *offset) + int *err, char **err_info, int64_t *offset) { FileHandler fh = (FileHandler)(wth->wslua_data); int retval = -1; @@ -246,7 +245,7 @@ wslua_filehandler_read_packet(wtap *wth, FILE_T wth_fh, wtap_rec *rec, Buffer *b CaptureInfo *fc = NULL; FrameInfo *fi = NULL; - INIT_FILEHANDLER_ROUTINE(read,FALSE,err,err_info); + INIT_FILEHANDLER_ROUTINE(read,false,err,err_info); /* Reset errno */ if (err) { @@ -257,7 +256,7 @@ wslua_filehandler_read_packet(wtap *wth, FILE_T wth_fh, wtap_rec *rec, Buffer *b rec->block = NULL; fp = push_File(L, wth_fh); - fc = push_CaptureInfo(L, wth, FALSE); + fc = push_CaptureInfo(L, wth, false); fi = push_FrameInfo(L, rec, buf); switch ( lua_pcall(L,3,1,1) ) { @@ -270,7 +269,7 @@ wslua_filehandler_read_packet(wtap *wth, FILE_T wth_fh, wtap_rec *rec, Buffer *b * succeed without advancing data offset. Should it fail instead? */ if (lua_type(L, -1) == LUA_TNUMBER) { - *offset = wslua_togint64(L, -1); + *offset = wslua_toint64(L, -1); retval = 1; break; } @@ -281,30 +280,30 @@ wslua_filehandler_read_packet(wtap *wth, FILE_T wth_fh, wtap_rec *rec, Buffer *b END_FILEHANDLER_ROUTINE(); - (*fp)->expired = TRUE; - (*fc)->expired = TRUE; - (*fi)->expired = TRUE; + (*fp)->expired = true; + (*fc)->expired = true; + (*fi)->expired = true; lua_settop(L,0); return (retval == 1); } -/* The classic wtap read routine. This returns TRUE if it found the next packet, - * else FALSE. +/* The classic wtap read routine. This returns true if it found the next packet, + * else false. * If it finds a frame/packet, it should set the pseudo-header info (ie, let Lua set it). * Also Lua needs to set data_offset to the beginning of the line we're returning. * This will be the seek_off parameter when this frame is re-read. */ -static gboolean +static bool wslua_filehandler_read(wtap *wth, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info, gint64 *offset) + int *err, char **err_info, int64_t *offset) { return wslua_filehandler_read_packet(wth, wth->fh, rec, buf, err, err_info, offset); } -static gboolean -wslua_filehandler_seek_read_packet(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) +static bool +wslua_filehandler_seek_read_packet(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { FileHandler fh = (FileHandler)(wth->wslua_data); int retval = -1; @@ -313,7 +312,7 @@ wslua_filehandler_seek_read_packet(wtap *wth, gint64 seek_off, wtap_rec *rec, Bu CaptureInfo *fc = NULL; FrameInfo *fi = NULL; - INIT_FILEHANDLER_ROUTINE(seek_read,FALSE,err,err_info); + INIT_FILEHANDLER_ROUTINE(seek_read,false,err,err_info); /* Reset errno */ if (err) { @@ -324,9 +323,9 @@ wslua_filehandler_seek_read_packet(wtap *wth, gint64 seek_off, wtap_rec *rec, Bu rec->block = NULL; fp = push_File(L, wth->random_fh); - fc = push_CaptureInfo(L, wth, FALSE); + fc = push_CaptureInfo(L, wth, false); fi = push_FrameInfo(L, rec, buf); - lua_pushnumber(L, (lua_Number)seek_off); + lua_pushinteger(L, (lua_Integer)seek_off); switch ( lua_pcall(L,4,1,1) ) { case 0: @@ -345,9 +344,9 @@ wslua_filehandler_seek_read_packet(wtap *wth, gint64 seek_off, wtap_rec *rec, Bu END_FILEHANDLER_ROUTINE(); - (*fp)->expired = TRUE; - (*fc)->expired = TRUE; - (*fi)->expired = TRUE; + (*fp)->expired = true; + (*fc)->expired = true; + (*fi)->expired = true; lua_settop(L,0); return (retval == 1); @@ -356,31 +355,31 @@ wslua_filehandler_seek_read_packet(wtap *wth, gint64 seek_off, wtap_rec *rec, Bu /* Default FileHandler:seek_read() implementation. * Do a standard file_seek() and then call FileHandler:read(). */ -static gboolean -wslua_filehandler_seek_read_default(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) +static bool +wslua_filehandler_seek_read_default(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { - gint64 offset = file_seek(wth->random_fh, seek_off, SEEK_SET, err); + int64_t offset = file_seek(wth->random_fh, seek_off, SEEK_SET, err); if (offset < 0) { - return FALSE; + return false; } return wslua_filehandler_read_packet(wth, wth->random_fh, rec, buf, err, err_info, &offset); } -/* Classic wtap seek_read function, called by wtap core. This must return TRUE on - * success, FALSE on error. +/* Classic wtap seek_read function, called by wtap core. This must return true on + * success, false on error. */ -static gboolean -wslua_filehandler_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, - int *err, gchar **err_info) +static bool +wslua_filehandler_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, Buffer *buf, + int *err, char **err_info) { FileHandler fh = (FileHandler)(wth->wslua_data); if (fh->removed) { /* Return success when removed during reloading Lua plugins */ - return TRUE; + return true; } if (fh->seek_read_ref != LUA_NOREF) { @@ -403,7 +402,7 @@ wslua_filehandler_close(wtap *wth) INIT_FILEHANDLER_ROUTINE(read_close,,NULL,NULL); fp = push_File(L, wth->fh); - fc = push_CaptureInfo(L, wth, FALSE); + fc = push_CaptureInfo(L, wth, false); switch ( lua_pcall(L,2,1,1) ) { case 0: @@ -415,8 +414,8 @@ wslua_filehandler_close(wtap *wth) remove_wth_priv(L, wth); - (*fp)->expired = TRUE; - (*fc)->expired = TRUE; + (*fp)->expired = true; + (*fc)->expired = true; lua_settop(L,0); return; @@ -435,7 +434,7 @@ wslua_filehandler_sequential_close(wtap *wth) INIT_FILEHANDLER_ROUTINE(seq_read_close,,NULL,NULL); fp = push_File(L, wth->fh); - fc = push_CaptureInfo(L, wth, FALSE); + fc = push_CaptureInfo(L, wth, false); switch ( lua_pcall(L,2,1,1) ) { case 0: @@ -445,8 +444,8 @@ wslua_filehandler_sequential_close(wtap *wth) END_FILEHANDLER_ROUTINE(); - (*fp)->expired = TRUE; - (*fc)->expired = TRUE; + (*fp)->expired = true; + (*fc)->expired = true; lua_settop(L,0); return; @@ -474,7 +473,7 @@ wslua_filehandler_can_write_encap(int encap, void* data) INIT_FILEHANDLER_ROUTINE(can_write_encap,WTAP_ERR_UNWRITABLE_ENCAP,NULL,NULL); - lua_pushnumber(L, encap); + lua_pushinteger(L, encap); switch ( lua_pcall(L,1,1,1) ) { case 0: @@ -497,21 +496,21 @@ wslua_filehandler_can_write_encap(int encap, void* data) } /* some declarations */ -static gboolean +static bool wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info); -static gboolean -wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info); + const uint8_t *pd, int *err, char **err_info); +static bool +wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err, char **err_info); /* The classic wtap dump_open function. - * This returns 1 (TRUE) on success. + * This returns true on success. */ -static int -wslua_filehandler_dump_open(wtap_dumper *wdh, int *err, gchar **err_info) +static bool +wslua_filehandler_dump_open(wtap_dumper *wdh, int *err, char **err_info) { FileHandler fh = (FileHandler)(wdh->wslua_data); - int retval = 0; + bool retval = false; lua_State* L = NULL; File *fp = NULL; CaptureInfoConst *fc = NULL; @@ -537,10 +536,10 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err, gchar **err_info) END_FILEHANDLER_ROUTINE(); - (*fp)->expired = TRUE; - (*fc)->expired = TRUE; + (*fp)->expired = true; + (*fc)->expired = true; - if (retval == 1) { + if (retval == true) { /* this is our file type - set the routines and settings into wtap */ if (fh->write_ref != LUA_NOREF) { @@ -548,7 +547,7 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err, gchar **err_info) } else { ws_warning("FileHandler was not set with a write function, even though write_open() returned true"); - return 0; + return false; } /* it's ok to not have a finish routine */ @@ -565,12 +564,12 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err, gchar **err_info) return retval; } -/* The classic wtap dump routine. This returns TRUE if it writes the current packet, - * else FALSE. +/* The classic wtap dump routine. This returns true if it writes the current + * packet, else false. */ -static gboolean +static bool wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec, - const guint8 *pd, int *err, gchar **err_info) + const uint8_t *pd, int *err, char **err_info) { FileHandler fh = (FileHandler)(wdh->wslua_data); int retval = -1; @@ -579,7 +578,7 @@ wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec, CaptureInfoConst *fc = NULL; FrameInfoConst *fi = NULL; - INIT_FILEHANDLER_ROUTINE(write,FALSE,err,err_info); + INIT_FILEHANDLER_ROUTINE(write,false,err,err_info); /* Reset errno */ if (err) { @@ -600,18 +599,18 @@ wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec, END_FILEHANDLER_ROUTINE(); - (*fp)->expired = TRUE; - (*fc)->expired = TRUE; - (*fi)->expired = TRUE; + (*fp)->expired = true; + (*fc)->expired = true; + (*fi)->expired = true; return (retval == 1); } -/* The classic wtap dump_finish routine. This returns TRUE if it - * writes out the last information cleanly, else FALSE. +/* The classic wtap dump_finish routine. This returns true if it + * writes out the last information cleanly, else false. */ -static gboolean -wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info) +static bool +wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err, char **err_info) { FileHandler fh = (FileHandler)(wdh->wslua_data); int retval = -1; @@ -619,7 +618,7 @@ wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info) File *fp = NULL; CaptureInfoConst *fc = NULL; - INIT_FILEHANDLER_ROUTINE(write_close,FALSE,err,err_info); + INIT_FILEHANDLER_ROUTINE(write_close,false,err,err_info); /* Reset errno */ if (err) { @@ -641,8 +640,8 @@ wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err, gchar **err_info) remove_wdh_priv(L, wdh); - (*fp)->expired = TRUE; - (*fc)->expired = TRUE; + (*fp)->expired = true; + (*fc)->expired = true; return (retval == 1); } @@ -671,7 +670,7 @@ static const struct supported_block_type block_type_proto[] = { { WTAP_BLOCK_FT_SPECIFIC_EVENT, BLOCK_NOT_SUPPORTED, 0, NULL } }; -#define NUM_LISTED_BLOCK_TYPES (sizeof block_type_proto / sizeof block_type_proto[0]) +#define NUM_LISTED_BLOCK_TYPES array_length(block_type_proto) WSLUA_CONSTRUCTOR FileHandler_new(lua_State* L) { /* Creates a new FileHandler */ @@ -680,15 +679,15 @@ WSLUA_CONSTRUCTOR FileHandler_new(lua_State* L) { #define WSLUA_ARG_FileHandler_new_INTERNAL_DESCRIPTION 3 /* Descriptive text about this file format, for internal display purposes only */ #define WSLUA_ARG_FileHandler_new_TYPE 4 /* The type of FileHandler, "r"/"w"/"rw" for reader/writer/both, include "m" for magic, "s" for strong heuristic */ - const gchar* description = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_DESCRIPTION); - const gchar* name = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_NAME); - const gchar* internal_description = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_INTERNAL_DESCRIPTION); - const gchar* type = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_TYPE); + const char* description = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_DESCRIPTION); + const char* name = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_NAME); + const char* internal_description = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_INTERNAL_DESCRIPTION); + const char* type = luaL_checkstring(L,WSLUA_ARG_FileHandler_new_TYPE); FileHandler fh = (FileHandler) g_malloc0(sizeof(struct _wslua_filehandler)); struct supported_block_type *supported_blocks; - fh->is_reader = (strchr(type,'r') != NULL) ? TRUE : FALSE; - fh->is_writer = (strchr(type,'w') != NULL) ? TRUE : FALSE; + fh->is_reader = (strchr(type,'r') != NULL) ? true : false; + fh->is_writer = (strchr(type,'w') != NULL) ? true : false; if (fh->is_reader && wtap_has_open_info(name)) { g_free(fh); @@ -706,7 +705,7 @@ WSLUA_CONSTRUCTOR FileHandler_new(lua_State* L) { fh->finfo.name = g_strdup(name); fh->finfo.default_file_extension = NULL; fh->finfo.additional_file_extensions = NULL; - fh->finfo.writing_must_seek = FALSE; + fh->finfo.writing_must_seek = false; supported_blocks = (struct supported_block_type *)g_memdup2(&block_type_proto, sizeof block_type_proto); /* * Add a list of options to the seciton block, interface block, and @@ -745,7 +744,7 @@ WSLUA_CONSTRUCTOR FileHandler_new(lua_State* L) { fh->write_close_ref = LUA_NOREF; fh->can_write_encap_ref = LUA_NOREF; - fh->registered = FALSE; + fh->registered = false; pushFileHandler(L,fh); WSLUA_RETURN(1); /* The newly created FileHandler object */ @@ -775,7 +774,7 @@ static int FileHandler__gc(lua_State* L _U_) { * a *reader* one MUST at least define read_open, read, and seek_read funcs; and * a *writer* one MUST at least define can_write_encap, write_open, and write funcs */ -static gboolean verify_filehandler_complete(FileHandler fh) { +static bool verify_filehandler_complete(FileHandler fh) { return ((fh->is_reader || fh->is_writer) && (!fh->is_reader || (fh->is_reader && @@ -839,10 +838,10 @@ WSLUA_FUNCTION wslua_register_filehandler(lua_State* L) { wtap_register_open_info(&oi, (strchr(fh->type,'s') != NULL)); } - fh->registered = TRUE; + fh->registered = true; registered_file_handlers = g_slist_prepend(registered_file_handlers, fh); - lua_pushnumber(L, fh->file_type); + lua_pushinteger(L, fh->file_type); WSLUA_RETURN(1); /* the new type number for this file reader/write */ } @@ -871,7 +870,7 @@ wslua_deregister_filehandler_work(FileHandler fh) wtap_deregister_open_info(fh->finfo.name); } - fh->registered = FALSE; + fh->registered = false; } WSLUA_FUNCTION wslua_deregister_filehandler(lua_State* L) { @@ -1043,7 +1042,7 @@ WSLUA_ATTRIBUTE_FUNC_SETTER(FileHandler,write_close); /* WSLUA_ATTRIBUTE FileHandler_type RO The internal file type. This is automatically set with a new number when the FileHandler is registered. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FileHandler,type,file_type); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FileHandler,type,file_type); /* WSLUA_ATTRIBUTE FileHandler_extensions RW One or more semicolon-separated file extensions that this file type usually uses. @@ -1053,7 +1052,7 @@ WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FileHandler,type,file_type); (Since 2.6) For writers, the first extension is used to suggest the default file extension. */ WSLUA_ATTRIBUTE_STRING_GETTER(FileHandler,extensions); -WSLUA_ATTRIBUTE_STRING_SETTER(FileHandler,extensions,TRUE); +WSLUA_ATTRIBUTE_STRING_SETTER(FileHandler,extensions,true); /* WSLUA_ATTRIBUTE FileHandler_writing_must_seek RW True if the ability to seek is required when writing this file format, else false. @@ -1085,7 +1084,7 @@ DIAG_ON_CAST_AWAY_CONST } WSLUA_ATTRIBUTE_GET(FileHandler,writes_name_resolution,{ \ - gboolean supports_name_resolution = FALSE; \ + bool supports_name_resolution = false; \ for (size_t i = 0; i < obj->finfo.num_supported_blocks; i++) { \ /* \ * If WTAP_BLOCK_NAME_RESOLUTION is supported, name \ @@ -1099,7 +1098,7 @@ WSLUA_ATTRIBUTE_GET(FileHandler,writes_name_resolution,{ \ lua_pushboolean(L, supports_name_resolution); \ }); WSLUA_ATTRIBUTE_SET(FileHandler,writes_name_resolution, { \ - gboolean supports_name_resolution; \ + bool supports_name_resolution; \ if (!lua_isboolean(L,-1) ) \ return luaL_error(L, "FileHandler's attribute`writes_name_resolution' must be a boolean"); \ supports_name_resolution = lua_toboolean(L,-1); \ @@ -1138,7 +1137,7 @@ DIAG_ON_CAST_AWAY_CONST } WSLUA_ATTRIBUTE_GET(FileHandler,supported_comment_types,{ \ - guint supported_comment_types = 0; \ + unsigned supported_comment_types = 0; \ for (size_t i = 0; i < obj->finfo.num_supported_blocks; i++) { \ size_t num_supported_options; \ const struct supported_option_type *supported_options; @@ -1207,15 +1206,15 @@ WSLUA_ATTRIBUTE_GET(FileHandler,supported_comment_types,{ \ break;\ } \ } \ - lua_pushnumber(L, (lua_Number)supported_comment_types); \ + lua_pushinteger(L, (lua_Integer)supported_comment_types); \ }); WSLUA_ATTRIBUTE_SET(FileHandler,supported_comment_types, { \ - guint supported_comment_types; \ + unsigned supported_comment_types; \ size_t num_supported_options; \ struct supported_option_type *supported_options; \ if (!lua_isnumber(L,-1) ) \ return luaL_error(L, "FileHandler's attribute`supported_comment_types' must be a number"); \ - supported_comment_types = wslua_toguint(L,-1); \ + supported_comment_types = wslua_touint(L,-1); \ /* \ * Update support for comments in the relevant block types; the entries \ * for comments in those types should be there. \ @@ -1344,7 +1343,7 @@ int wslua_deregister_filehandlers(lua_State* L _U_) { g_free(fh->type); memset(fh, 0, sizeof(*fh)); - fh->removed = TRUE; + fh->removed = true; proto_add_deregistered_data(fh); } g_slist_free(registered_file_handlers); diff --git a/epan/wslua/wslua_frame_info.c b/epan/wslua/wslua_frame_info.c index 401abd73..2fa7f755 100644 --- a/epan/wslua/wslua_frame_info.c +++ b/epan/wslua/wslua_frame_info.c @@ -13,6 +13,7 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "config.h" +#define WS_LOG_DOMAIN LOG_DOMAIN_WSLUA #include "wslua_file_common.h" #include <lua.h> @@ -37,15 +38,13 @@ WSLUA_CLASS_DEFINE(FrameInfo,FAIL_ON_NULL_OR_EXPIRED("FrameInfo")); whereas when the Lua plugin's `FileHandler.write()` function is invoked, the `FrameInfo` object passed in should have its fields read-from/get, to write that frame information to the file. - - @since 1.11.3 */ FrameInfo* push_FrameInfo(lua_State* L, wtap_rec *rec, Buffer* buf) { FrameInfo f = (FrameInfo) g_malloc0(sizeof(struct _wslua_phdr)); f->rec = rec; f->buf = buf; - f->expired = FALSE; + f->expired = false; return pushFrameInfo(L,f); } @@ -73,9 +72,9 @@ WSLUA_METHOD FrameInfo_read_data(lua_State* L) { #define WSLUA_ARG_FrameInfo_read_data_LENGTH 3 /* The number of bytes to read from the file at the current cursor position. */ FrameInfo fi = checkFrameInfo(L,1); File fh = checkFile(L,WSLUA_ARG_FrameInfo_read_data_FILE); - guint32 len = wslua_checkguint32(L, WSLUA_ARG_FrameInfo_read_data_LENGTH); + uint32_t len = wslua_checkuint32(L, WSLUA_ARG_FrameInfo_read_data_LENGTH); int err = 0; - gchar *err_info = NULL; + char *err_info = NULL; if (!fi->buf || !fh->file) { luaL_error(L, "FrameInfo read_data() got null buffer or file pointer internally"); @@ -83,17 +82,17 @@ WSLUA_METHOD FrameInfo_read_data(lua_State* L) { } if (!wtap_read_packet_bytes(fh->file, fi->buf, len, &err, &err_info)) { - lua_pushboolean(L, FALSE); + lua_pushboolean(L, false); if (err_info) { lua_pushstring(L, err_info); g_free(err_info); /* is this right? */ } else lua_pushnil(L); - lua_pushnumber(L, err); + lua_pushinteger(L, err); return 3; } - lua_pushboolean(L, TRUE); + lua_pushboolean(L, true); WSLUA_RETURN(1); /* True if succeeded, else returns false along with the error number and string error description. */ } @@ -109,10 +108,10 @@ static int FrameInfo__gc(lua_State* L) { static int FrameInfo_get_comment (lua_State* L) { FrameInfo fi = checkFrameInfo(L,1); #define FRAMEINFO_COMMENTS_TABLE 2 - gchar *comment = NULL; + char *comment = NULL; wtap_block_t block = NULL; - guint i = 0; - guint n_comments = 0; + unsigned i = 0; + unsigned n_comments = 0; block = fi->rec->block; // XXX - how to get the user-edited block, if any? @@ -120,7 +119,7 @@ static int FrameInfo_get_comment (lua_State* L) { lua_createtable(L, n_comments, 0); for (i = 0; i < n_comments; i++) { comment = NULL; - lua_pushnumber(L, i+1); + lua_pushinteger(L, i+1); if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_nth_string_option_value(block, OPT_COMMENT, i, &comment)) { lua_pushstring(L, comment); @@ -139,10 +138,10 @@ static int FrameInfo_set_comment (lua_State* L) { #define FRAMEINFO_COMMENTS_NEWTABLE 2 #define FRAMEINFO_COMMENTS_NEWCOMMENT 2 size_t len = 0; - gchar *comment = NULL; + char *comment = NULL; wtap_block_t block = NULL; - guint i = 0; - guint n_comments = 0; + unsigned i = 0; + unsigned n_comments = 0; if(fi->rec->block != NULL) { block = fi->rec->block; @@ -162,7 +161,7 @@ static int FrameInfo_set_comment (lua_State* L) { if (lua_istable(L, FRAMEINFO_COMMENTS_NEWTABLE)) { for (lua_pushnil(L); lua_next(L, FRAMEINFO_COMMENTS_NEWTABLE); ) { if (lua_isstring(L,-1)) { - comment = (gchar *)luaL_checklstring(L,-1,&len); + comment = (char *)luaL_checklstring(L,-1,&len); wtap_block_add_string_option(block, OPT_COMMENT, comment, len); } else if (! lua_isnil(L,-1) ) { return luaL_error(L,"only strings should be in the table"); @@ -171,7 +170,7 @@ static int FrameInfo_set_comment (lua_State* L) { } } else if (lua_isstring(L, FRAMEINFO_COMMENTS_NEWCOMMENT)) { - comment = (gchar *)luaL_checklstring(L,FRAMEINFO_COMMENTS_NEWCOMMENT,&len); + comment = (char *)luaL_checklstring(L,FRAMEINFO_COMMENTS_NEWCOMMENT,&len); wtap_block_add_string_option(block, OPT_COMMENT, comment, len); } else { @@ -233,13 +232,13 @@ static int FrameInfo_set_data (lua_State* L) { if (lua_isstring(L,2)) { size_t len = 0; - const gchar* s = luaL_checklstring(L,2,&len); + const char* s = luaL_checklstring(L,2,&len); /* Make sure we have enough room for the packet */ ws_buffer_assure_space(fi->buf, len); memcpy(ws_buffer_start_ptr(fi->buf), s, len); - fi->rec->rec_header.packet_header.caplen = (guint32) len; - fi->rec->rec_header.packet_header.len = (guint32) len; + fi->rec->rec_header.packet_header.caplen = (uint32_t) len; + fi->rec->rec_header.packet_header.len = (uint32_t) len; } else luaL_error(L, "FrameInfo's attribute 'data' must be a Lua string"); @@ -260,30 +259,30 @@ static int FrameInfo_get_data (lua_State* L) { /* WSLUA_ATTRIBUTE FrameInfo_rec_type RW The record type of the packet frame See `wtap_rec_types` for values. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,rec_type,rec->rec_type); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,rec_type,rec->rec_type,guint); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfo,rec_type,rec->rec_type); +WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(FrameInfo,rec_type,rec->rec_type,unsigned); /* WSLUA_ATTRIBUTE FrameInfo_flags RW The presence flags of the packet frame. See `wtap_presence_flags` for bit values. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,flags,rec->presence_flags); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,flags,rec->presence_flags,guint32); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfo,flags,rec->presence_flags); +WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(FrameInfo,flags,rec->presence_flags,uint32_t); /* WSLUA_ATTRIBUTE FrameInfo_captured_length RW The captured packet length, and thus the length of the buffer passed to the `FrameInfo.data` field. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,captured_length,rec->rec_header.packet_header.caplen); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,captured_length,rec->rec_header.packet_header.caplen,guint32); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfo,captured_length,rec->rec_header.packet_header.caplen); +WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(FrameInfo,captured_length,rec->rec_header.packet_header.caplen,uint32_t); /* WSLUA_ATTRIBUTE FrameInfo_original_length RW The on-the-wire packet length, which may be longer than the `captured_length`. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,original_length,rec->rec_header.packet_header.len); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,original_length,rec->rec_header.packet_header.len,guint32); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfo,original_length,rec->rec_header.packet_header.len); +WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(FrameInfo,original_length,rec->rec_header.packet_header.len,uint32_t); /* WSLUA_ATTRIBUTE FrameInfo_encap RW The packet encapsulation type for the frame/packet, if the file supports per-packet types. See `wtap_encaps` for possible packet encapsulation types to use as the value for this field. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfo,encap,rec->rec_header.packet_header.pkt_encap); -WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(FrameInfo,encap,rec->rec_header.packet_header.pkt_encap,int); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfo,encap,rec->rec_header.packet_header.pkt_encap); +WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(FrameInfo,encap,rec->rec_header.packet_header.pkt_encap,int); /* This table is ultimately registered as a sub-table of the class' metatable, * and if __index/__newindex is invoked then it calls the appropriate function @@ -321,15 +320,13 @@ WSLUA_CLASS_DEFINE(FrameInfoConst,FAIL_ON_NULL_OR_EXPIRED("FrameInfo")); A constant FrameInfo object, passed into Lua as an argument by the FileHandler write callback function. This has similar attributes/properties as FrameInfo, but the fields can only be read from, not written to. - - @since 1.11.3 */ -FrameInfoConst* push_FrameInfoConst(lua_State* L, const wtap_rec *rec, const guint8 *pd) { +FrameInfoConst* push_FrameInfoConst(lua_State* L, const wtap_rec *rec, const uint8_t *pd) { FrameInfoConst f = (FrameInfoConst) g_malloc(sizeof(struct _wslua_const_phdr)); f->rec = rec; f->pd = pd; - f->expired = FALSE; + f->expired = false; return pushFrameInfoConst(L,f); } @@ -357,7 +354,7 @@ WSLUA_METHOD FrameInfoConst_write_data(lua_State* L) { #define WSLUA_OPTARG_FrameInfoConst_write_data_LENGTH 3 /* The number of bytes to write to the file at the current cursor position, or all if not supplied. */ FrameInfoConst fi = checkFrameInfoConst(L,1); File fh = checkFile(L,WSLUA_ARG_FrameInfoConst_write_data_FILE); - guint32 len = wslua_optguint32(L, WSLUA_OPTARG_FrameInfoConst_write_data_LENGTH, fi->rec ? fi->rec->rec_header.packet_header.caplen:0); + uint32_t len = wslua_optuint32(L, WSLUA_OPTARG_FrameInfoConst_write_data_LENGTH, fi->rec ? fi->rec->rec_header.packet_header.caplen:0); int err = 0; if (!fi->pd || !fi->rec || !fh->wdh) { @@ -369,13 +366,13 @@ WSLUA_METHOD FrameInfoConst_write_data(lua_State* L) { len = fi->rec->rec_header.packet_header.caplen; if (!wtap_dump_file_write(fh->wdh, fi->pd, (size_t)(len), &err)) { - lua_pushboolean(L, FALSE); + lua_pushboolean(L, false); lua_pushfstring(L, "FrameInfoConst write_data() error: %s", g_strerror(err)); - lua_pushnumber(L, err); + lua_pushinteger(L, err); return 3; } - lua_pushboolean(L, TRUE); + lua_pushboolean(L, true); WSLUA_RETURN(1); /* True if succeeded, else returns false along with the error number and string error description. */ } @@ -392,10 +389,10 @@ static int FrameInfoConst__gc(lua_State* L) { static int FrameInfoConst_get_comment (lua_State* L) { FrameInfoConst fi = checkFrameInfoConst(L,1); #define FRAMEINFOCONST_COMMENTS_TABLE 2 - gchar *comment = NULL; + char *comment = NULL; wtap_block_t block = NULL; - guint i = 0; - guint n_comments = 0; + unsigned i = 0; + unsigned n_comments = 0; block = fi->rec->block; // XXX - how to get the user-edited block, if any? @@ -403,7 +400,7 @@ static int FrameInfoConst_get_comment (lua_State* L) { lua_createtable(L, n_comments, 0); for (i = 0; i < n_comments; i++) { comment = NULL; - lua_pushnumber(L, i+1); + lua_pushinteger(L, i+1); if (WTAP_OPTTYPE_SUCCESS == wtap_block_get_nth_string_option_value(block, OPT_COMMENT, i, &comment)) { lua_pushstring(L, comment); @@ -444,21 +441,21 @@ static int FrameInfoConst_get_data (lua_State* L) { } /* WSLUA_ATTRIBUTE FrameInfoConst_rec_type RO The record type of the packet frame - see `wtap_presence_flags` for values. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,rec_type,rec->rec_type); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfoConst,rec_type,rec->rec_type); /* WSLUA_ATTRIBUTE FrameInfoConst_flags RO The presence flags of the packet frame - see `wtap_presence_flags` for bits. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,flags,rec->presence_flags); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfoConst,flags,rec->presence_flags); /* WSLUA_ATTRIBUTE FrameInfoConst_captured_length RO The captured packet length, and thus the length of the buffer in the FrameInfoConst.data field. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,captured_length,rec->rec_header.packet_header.caplen); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfoConst,captured_length,rec->rec_header.packet_header.caplen); /* WSLUA_ATTRIBUTE FrameInfoConst_original_length RO The on-the-wire packet length, which may be longer than the `captured_length`. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,original_length,rec->rec_header.packet_header.len); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfoConst,original_length,rec->rec_header.packet_header.len); /* WSLUA_ATTRIBUTE FrameInfoConst_encap RO The packet encapsulation type, if the file supports per-packet types. See `wtap_encaps` for possible packet encapsulation types to use as the value for this field. */ -WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(FrameInfoConst,encap,rec->rec_header.packet_header.pkt_encap); +WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(FrameInfoConst,encap,rec->rec_header.packet_header.pkt_encap); WSLUA_ATTRIBUTES FrameInfoConst_attributes[] = { WSLUA_ATTRIBUTE_ROREG(FrameInfoConst,rec_type), diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c index fe6ab5cf..469c245a 100644 --- a/epan/wslua/wslua_gui.c +++ b/epan/wslua/wslua_gui.c @@ -11,6 +11,7 @@ */ #include "config.h" +#define WS_LOG_DOMAIN LOG_DOMAIN_WSLUA #include <epan/wmem_scopes.h> @@ -18,7 +19,7 @@ /* WSLUA_MODULE Gui GUI Support */ -static const funnel_ops_t* ops = NULL; +static const funnel_ops_t* ops; struct _lua_menu_data { lua_State* L; @@ -26,7 +27,7 @@ struct _lua_menu_data { }; static int menu_cb_error_handler(lua_State* L) { - const gchar* error = lua_tostring(L,1); + const char* error = lua_tostring(L,1); report_failure("Lua: Error during execution of Menu callback:\n %s",error); return 0; } @@ -36,7 +37,7 @@ WSLUA_FUNCTION wslua_gui_enabled(lua_State* L) { /* Checks if we're running insi WSLUA_RETURN(1); /* Boolean `true` if a GUI is available, `false` if it isn't. */ } -static void lua_menu_callback(gpointer data) { +static void lua_menu_callback(void *data) { struct _lua_menu_data* md = (struct _lua_menu_data *)data; lua_State* L = md->L; @@ -74,37 +75,42 @@ WSLUA_FUNCTION wslua_register_menu(lua_State* L) { /* Register a menu item in o * MENU_PACKET_ANALYZE_UNSORTED: menu:Analyze[] * MENU_PACKET_STAT_UNSORTED: menu:Statistics[] * MENU_STAT_GENERIC: menu:Statistics[], first section - * MENU_STAT_CONVERSATION_LIST: menu:Statistics[Conversation List] - * MENU_STAT_ENDPOINT_LIST: menu:Statistics[Endpoint List] * MENU_STAT_RESPONSE_TIME: menu:Statistics[Service Response Time] - * MENU_STAT_RSERPOOL = menu:Statistics[Reliable Server Pooling (RSerPool)] - * MENU_STAT_TELEPHONY: menu:Telephony[] - * MENU_STAT_TELEPHONY_ANSI: menu:Telephony[ANSI] - * MENU_STAT_TELEPHONY_GSM: menu:Telephony[GSM] - * MENU_STAT_TELEPHONY_LTE: menu:Telephony[LTE] - * MENU_STAT_TELEPHONY_MTP3: menu:Telephony[MTP3] - * MENU_STAT_TELEPHONY_SCTP: menu:Telephony[SCTP] - * MENU_ANALYZE: menu:Analyze[] - * MENU_ANALYZE_CONVERSATION: menu:Analyze[Conversation Filter] + * MENU_STAT_RSERPOOL: menu:Statistics[Reliable Server Pooling (RSerPool)] + * MENU_TELEPHONY_UNSORTED: menu:Telephony[] + * MENU_TELEPHONY_ANSI: menu:Telephony[ANSI] + * MENU_TELEPHONY_GSM: menu:Telephony[GSM] + * MENU_TELEPHONY_3GPP_UU: menu:Telephony[3GPP Uu] + * MENU_TELEPHONY_MTP3: menu:Telephony[MTP3] + * MENU_TELEPHONY_SCTP: menu:Telephony[SCTP] * MENU_TOOLS_UNSORTED: menu:Tools[] Valid log (Logray) items are: * MENU_LOG_ANALYZE_UNSORTED: menu:Analyze[] - * MENU_LOG_STAT_UNSORTED = 16 + * MENU_LOG_STAT_UNSORTED: menu:Statistics[] The following are deprecated and shouldn't be used in new code: + * MENU_ANALYZE_CONVERSATION_FILTER, menu:Analyze[Conversation Filter] registration is not yet supported in Lua + * MENU_STAT_CONVERSATION_LIST, menu:Statistics[Conversations] registration is not yet supported in Lua + * MENU_STAT_ENDPOINT_LIST, menu:Statistics[Endpoints] registration is not yet supported in Lua * MENU_ANALYZE_UNSORTED, superseded by MENU_PACKET_ANALYZE_UNSORTED * MENU_ANALYZE_CONVERSATION, superseded by MENU_ANALYZE_CONVERSATION_FILTER * MENU_STAT_CONVERSATION, superseded by MENU_STAT_CONVERSATION_LIST * MENU_STAT_ENDPOINT, superseded by MENU_STAT_ENDPOINT_LIST * MENU_STAT_RESPONSE, superseded by MENU_STAT_RESPONSE_TIME * MENU_STAT_UNSORTED, superseded by MENU_PACKET_STAT_UNSORTED + * MENU_STAT_TELEPHONY, superseded by MENU_TELEPHONY_UNSORTED + * MENU_STAT_TELEPHONY_ANSI, superseded by MENU_TELEPHONY_ANSI + * MENU_STAT_TELEPHONY_GSM, superseded by MENU_TELEPHONY_GSM + * MENU_STAT_TELEPHONY_3GPP_UU, superseded by MENU_TELEPHONY_3GPP_UU + * MENU_STAT_TELEPHONY_MTP3, superseded by MENU_TELEPHONY_MTP3 + * MENU_STAT_TELEPHONY_SCTP, superseded by MENU_TELEPHONY_SCTP */ - const gchar* name = luaL_checkstring(L,WSLUA_ARG_register_menu_NAME); + const char* name = luaL_checkstring(L,WSLUA_ARG_register_menu_NAME); struct _lua_menu_data* md; - gboolean retap = FALSE; - register_stat_group_t group = (register_stat_group_t)wslua_optguint(L,WSLUA_OPTARG_register_menu_GROUP,REGISTER_STAT_GROUP_GENERIC); + bool retap = false; + register_stat_group_t group = (register_stat_group_t)wslua_optuint(L,WSLUA_OPTARG_register_menu_GROUP,REGISTER_STAT_GROUP_GENERIC); if ( group > REGISTER_TOOLS_GROUP_UNSORTED) { WSLUA_OPTARG_ERROR(register_menu,GROUP,"Must be a defined MENU_*"); @@ -144,7 +150,7 @@ void wslua_deregister_menus(void) { * @return Always returns 0 */ static int packet_menu_cb_error_handler(lua_State* L) { - const gchar* error = lua_tostring(L,1); + const char* error = lua_tostring(L,1); report_failure("Lua: Error During execution of Packet Menu Callback:\n %s",error); return 0; } @@ -156,7 +162,7 @@ static int packet_menu_cb_error_handler(lua_State* L) { * @param data Lua menu data * @param finfo_array packet data */ -static void lua_custom_packet_menu_callback(gpointer data, GPtrArray *finfo_array) { +static void lua_custom_packet_menu_callback(void *data, GPtrArray *finfo_array) { // _lua_menu_data is State + the integer index of a callback. struct _lua_menu_data* md = (struct _lua_menu_data *)data; lua_State* L = md->L; @@ -167,7 +173,7 @@ static void lua_custom_packet_menu_callback(gpointer data, GPtrArray *finfo_arra // Push the packet data as arguments to the Lua callback: int items_found = 0; - for (guint i = 0; i < finfo_array->len; i ++) { + for (unsigned i = 0; i < finfo_array->len; i ++) { field_info *fi = (field_info *)g_ptr_array_index (finfo_array, i); push_FieldInfo(L, fi); items_found++; @@ -198,11 +204,11 @@ WSLUA_FUNCTION wslua_register_packet_menu(lua_State* L) { /* Register a menu it #define WSLUA_ARG_register_packet_menu_ACTION 2 /* The function to be called when the menu item is invoked. The function must take a variable number of arguments and return nothing. The arguments will be FieldInfo objects, one for each field present in the selected packet. */ #define WSLUA_OPTARG_register_packet_menu_REQUIRED_FIELDS 3 /* A comma-separated list of packet fields (e.g., http.host,dns.qry.name) which all must be present for the menu to be displayed. If omitted, the packet menu will be displayed for all packets. */ - const gchar* name = luaL_checkstring(L,WSLUA_ARG_register_packet_menu_NAME); - const gchar* required_fields = luaL_optstring(L,WSLUA_OPTARG_register_packet_menu_REQUIRED_FIELDS,""); + const char* name = luaL_checkstring(L,WSLUA_ARG_register_packet_menu_NAME); + const char* required_fields = luaL_optstring(L,WSLUA_OPTARG_register_packet_menu_REQUIRED_FIELDS,""); struct _lua_menu_data* md; - gboolean retap = FALSE; + bool retap = false; if (!lua_isfunction(L,WSLUA_ARG_register_packet_menu_ACTION)) { WSLUA_ARG_ERROR(register_packet_menu,ACTION,"Must be a function"); @@ -230,15 +236,15 @@ struct _dlg_cb_data { }; static int dlg_cb_error_handler(lua_State* L) { - const gchar* error = lua_tostring(L,1); + const char* error = lua_tostring(L,1); report_failure("Lua: Error during execution of Dialog callback:\n %s",error); return 0; } -static void lua_dialog_cb(gchar** user_input, void* data) { +static void lua_dialog_cb(char** user_input, void* data) { struct _dlg_cb_data* dcbd = (struct _dlg_cb_data *)data; int i = 0; - gchar* input; + char* input; lua_State* L = dcbd->L; lua_settop(L,0); @@ -279,7 +285,7 @@ struct _close_cb_data { static int text_win_close_cb_error_handler(lua_State* L) { - const gchar* error = lua_tostring(L,1); + const char* error = lua_tostring(L,1); report_failure("Lua: Error during execution of TextWindow close callback:\n %s",error); return 0; } @@ -315,7 +321,7 @@ static void text_win_close_cb(void* data) { g_free(cbd->wslua_tw); g_free(cbd); } else { - cbd->wslua_tw->expired = TRUE; + cbd->wslua_tw->expired = true; } } @@ -354,7 +360,7 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* /* WSLUA_MOREARGS new_dialog Strings to be used as labels of the dialog's fields. Each string creates a new labeled field. The first field is required. Instead of a string it is possible to provide tables with fields 'name' and 'value' of type string. Then the created dialog's field will be labeled with the content of name and prefilled with the content of value.*/ - const gchar* title; + const char* title; int top = lua_gettop(L); int i; GPtrArray* field_names; @@ -402,10 +408,10 @@ Instead of a string it is possible to provide tables with fields 'name' and 'val { if (lua_isstring(L, i)) { - gchar* field_name = g_strdup(luaL_checkstring(L, i)); - gchar* field_value = g_strdup(""); - g_ptr_array_add(field_names, (gpointer)field_name); - g_ptr_array_add(field_values, (gpointer)field_value); + char* field_name = g_strdup(luaL_checkstring(L, i)); + char* field_value = g_strdup(""); + g_ptr_array_add(field_names, (void *)field_name); + g_ptr_array_add(field_values, (void *)field_value); } else if (lua_istable(L, i)) { @@ -416,27 +422,27 @@ Instead of a string it is possible to provide tables with fields 'name' and 'val { lua_pop(L, 2); - g_ptr_array_free(field_names, TRUE); - g_ptr_array_free(field_values, TRUE); + g_ptr_array_free(field_names, true); + g_ptr_array_free(field_values, true); g_free(dcbd); WSLUA_ERROR(new_dialog, "All fields must be strings or a table with a string field 'name'."); return 0; } - gchar* field_name = g_strdup(luaL_checkstring(L, -2)); - gchar* field_value = lua_isstring(L, -1) ? + char* field_name = g_strdup(luaL_checkstring(L, -2)); + char* field_value = lua_isstring(L, -1) ? g_strdup(luaL_checkstring(L, -1)) : g_strdup(""); - g_ptr_array_add(field_names, (gpointer)field_name); - g_ptr_array_add(field_values, (gpointer)field_value); + g_ptr_array_add(field_names, (void *)field_name); + g_ptr_array_add(field_values, (void *)field_value); lua_pop(L, 2); } else { - g_ptr_array_free(field_names, TRUE); - g_ptr_array_free(field_values, TRUE); + g_ptr_array_free(field_names, true); + g_ptr_array_free(field_values, true); g_free(dcbd); WSLUA_ERROR(new_dialog, "All fields must be strings or a table with a string field 'name'."); return 0; @@ -446,10 +452,10 @@ Instead of a string it is possible to provide tables with fields 'name' and 'val g_ptr_array_add(field_names, NULL); g_ptr_array_add(field_values, NULL); - ops->new_dialog(ops->ops_id, title, (const gchar**)(field_names->pdata), (const gchar**)(field_values->pdata), lua_dialog_cb, dcbd, g_free); + ops->new_dialog(ops->ops_id, title, (const char**)(field_names->pdata), (const char**)(field_values->pdata), lua_dialog_cb, dcbd, g_free); - g_ptr_array_free(field_names, TRUE); - g_ptr_array_free(field_values, TRUE); + g_ptr_array_free(field_names, true); + g_ptr_array_free(field_values, true); WSLUA_RETURN(0); } @@ -532,10 +538,10 @@ WSLUA_CONSTRUCTOR ProgDlg_new(lua_State* L) { /* ProgDlg pd = (ProgDlg)g_malloc(sizeof(struct _wslua_progdlg)); pd->title = g_strdup(luaL_optstring(L,WSLUA_OPTARG_ProgDlg_new_TITLE,"Progress")); pd->task = g_strdup(luaL_optstring(L,WSLUA_OPTARG_ProgDlg_new_TASK,"")); - pd->stopped = FALSE; + pd->stopped = false; if (ops->new_progress_window) { - pd->pw = ops->new_progress_window(ops->ops_id, pd->title, pd->task, TRUE, &(pd->stopped)); + pd->pw = ops->new_progress_window(ops->ops_id, pd->title, pd->task, true, &(pd->stopped)); } else { g_free (pd); WSLUA_ERROR(ProgDlg_new, "GUI not available"); @@ -552,7 +558,7 @@ WSLUA_METHOD ProgDlg_update(lua_State* L) { /* Sets the progress dialog's progre #define WSLUA_OPTARG_ProgDlg_update_TASK 3 /* Task name. Currently ignored. Defaults to empty string (""). */ ProgDlg pd = checkProgDlg(L,1); double pr = lua_tonumber(L,WSLUA_ARG_ProgDlg_update_PROGRESS); - const gchar* task = luaL_optstring(L,WSLUA_OPTARG_ProgDlg_update_TASK,""); + const char* task = luaL_optstring(L,WSLUA_OPTARG_ProgDlg_update_TASK,""); if (!ops->update_progress) { WSLUA_ERROR(ProgDlg_update,"GUI not available"); @@ -699,7 +705,7 @@ WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /* */ #define WSLUA_OPTARG_TextWindow_new_TITLE 1 /* Title of the new window. Optional. Defaults to "Untitled Window". */ - const gchar* title; + const char* title; TextWindow tw = NULL; struct _close_cb_data* default_cbd; @@ -710,7 +716,7 @@ WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /* title = luaL_optstring(L,WSLUA_OPTARG_TextWindow_new_TITLE, "Untitled Window"); tw = g_new(struct _wslua_tw, 1); - tw->expired = FALSE; + tw->expired = false; tw->ws_tw = ops->new_text_window(ops->ops_id, title); default_cbd = g_new(struct _close_cb_data, 1); @@ -765,7 +771,7 @@ WSLUA_METHOD TextWindow_set(lua_State* L) { /* Sets the text to be displayed. */ #define WSLUA_ARG_TextWindow_set_TEXT 2 /* The text to be displayed. */ TextWindow tw = checkTextWindow(L,1); - const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_set_TEXT); + const char* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_set_TEXT); if (!ops->set_text) { WSLUA_ERROR(TextWindow_set,"GUI not available"); @@ -781,7 +787,7 @@ WSLUA_METHOD TextWindow_set(lua_State* L) { /* Sets the text to be displayed. */ WSLUA_METHOD TextWindow_append(lua_State* L) { /* Appends text to the current window contents. */ #define WSLUA_ARG_TextWindow_append_TEXT 2 /* The text to be appended. */ TextWindow tw = checkTextWindow(L,1); - const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_append_TEXT); + const char* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_append_TEXT); if (!ops->append_text) { WSLUA_ERROR(TextWindow_append,"GUI not available"); @@ -797,7 +803,7 @@ WSLUA_METHOD TextWindow_append(lua_State* L) { /* Appends text to the current wi WSLUA_METHOD TextWindow_prepend(lua_State* L) { /* Prepends text to the current window contents. */ #define WSLUA_ARG_TextWindow_prepend_TEXT 2 /* The text to be prepended. */ TextWindow tw = checkTextWindow(L,1); - const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_prepend_TEXT); + const char* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_prepend_TEXT); if (!ops->prepend_text) { WSLUA_ERROR(TextWindow_prepend,"GUI not available"); @@ -826,7 +832,7 @@ WSLUA_METHOD TextWindow_clear(lua_State* L) { /* Erases all of the text in the w WSLUA_METHOD TextWindow_get_text(lua_State* L) { /* Get the text of the window. */ TextWindow tw = checkTextWindow(L,1); - const gchar* text; + const char* text; if (!ops->get_text) { WSLUA_ERROR(TextWindow_get_text,"GUI not available"); @@ -861,7 +867,7 @@ static int TextWindow__gc(lua_State* L) { return 0; if (!tw->expired) { - tw->expired = TRUE; + tw->expired = true; if (ops->destroy_text_window) { ops->destroy_text_window(tw->ws_tw); } @@ -877,7 +883,7 @@ WSLUA_METHOD TextWindow_set_editable(lua_State* L) { /* Make this text window ed #define WSLUA_OPTARG_TextWindow_set_editable_EDITABLE 2 /* `true` to make the text editable, `false` otherwise. Defaults to `true`. */ TextWindow tw = checkTextWindow(L,1); - gboolean editable = wslua_optbool(L,WSLUA_OPTARG_TextWindow_set_editable_EDITABLE,TRUE); + bool editable = wslua_optbool(L,WSLUA_OPTARG_TextWindow_set_editable_EDITABLE,true); if (!ops->set_editable) { WSLUA_ERROR(TextWindow_set_editable,"GUI not available"); @@ -895,7 +901,7 @@ typedef struct _wslua_bt_cb_t { int wslua_tw_ref; } wslua_bt_cb_t; -static gboolean wslua_button_callback(funnel_text_window_t* ws_tw, void* data) { +static bool wslua_button_callback(funnel_text_window_t* ws_tw, void* data) { wslua_bt_cb_t* cbd = (wslua_bt_cb_t *)data; lua_State* L = cbd->L; (void) ws_tw; /* ws_tw is unused since we need wslua_tw_ref and it is stored in cbd */ @@ -922,7 +928,7 @@ static gboolean wslua_button_callback(funnel_text_window_t* ws_tw, void* data) { break; } - return TRUE; + return true; } WSLUA_METHOD TextWindow_add_button(lua_State* L) { @@ -930,7 +936,7 @@ WSLUA_METHOD TextWindow_add_button(lua_State* L) { #define WSLUA_ARG_TextWindow_add_button_LABEL 2 /* The button label. */ #define WSLUA_ARG_TextWindow_add_button_FUNCTION 3 /* The Lua function to be called when the button is pressed. */ TextWindow tw = checkTextWindow(L,1); - const gchar* label = luaL_checkstring(L,WSLUA_ARG_TextWindow_add_button_LABEL); + const char* label = luaL_checkstring(L,WSLUA_ARG_TextWindow_add_button_LABEL); funnel_bt_t* fbt; wslua_bt_cb_t* cbd; @@ -1042,7 +1048,7 @@ WSLUA_FUNCTION wslua_open_capture_file(lua_State* L) { /* Open and display a cap } if (! ops->open_file(ops->ops_id, fname, filter, &error) ) { - lua_pushboolean(L,FALSE); + lua_pushboolean(L,false); if (error) { lua_pushstring(L,error); @@ -1052,7 +1058,7 @@ WSLUA_FUNCTION wslua_open_capture_file(lua_State* L) { /* Open and display a cap return 2; } else { - lua_pushboolean(L,TRUE); + lua_pushboolean(L,true); return 1; } } @@ -1108,8 +1114,8 @@ WSLUA_FUNCTION wslua_get_color_filter_slot(lua_State* L) { /* |10 |e0e0e0 |{set:cellbgcolor:#e0e0e0} gray |=== */ - guint8 row = (guint8)luaL_checkinteger(L, WSLUA_ARG_get_color_filter_slot_ROW); - gchar* filter_str = NULL; + uint8_t row = (uint8_t)luaL_checkinteger(L, WSLUA_ARG_get_color_filter_slot_ROW); + char* filter_str = NULL; if (!ops->get_color_filter_slot) { WSLUA_ERROR(get_color_filter_slot, "GUI not available"); @@ -1165,8 +1171,8 @@ WSLUA_FUNCTION wslua_set_color_filter_slot(lua_State* L) { /* */ #define WSLUA_ARG_set_color_filter_slot_TEXT 2 /* The https://gitlab.com/wireshark/wireshark/-/wikis/DisplayFilters[display filter] for selecting packets to be colorized . */ - guint8 row = (guint8)luaL_checkinteger(L,WSLUA_ARG_set_color_filter_slot_ROW); - const gchar* filter_str = luaL_checkstring(L,WSLUA_ARG_set_color_filter_slot_TEXT); + uint8_t row = (uint8_t)luaL_checkinteger(L,WSLUA_ARG_set_color_filter_slot_ROW); + const char* filter_str = luaL_checkstring(L,WSLUA_ARG_set_color_filter_slot_TEXT); if (!ops->set_color_filter_slot) { WSLUA_ERROR(set_color_filter_slot, "GUI not available"); diff --git a/epan/wslua/wslua_int64.c b/epan/wslua/wslua_int64.c index 17c00f06..b7b7d3c8 100644 --- a/epan/wslua/wslua_int64.c +++ b/epan/wslua/wslua_int64.c @@ -25,7 +25,7 @@ either expressed or implied, of the FreeBSD Project. /* WSLUA_MODULE Int64 Handling 64-bit Integers - Lua uses one single number representation which can be chosen at compile time and since it is often set to IEEE 754 double precision floating point, one cannot store 64 bit integers with full precision. + Lua uses one single number representation, which is chosen at compile time, and since it is often set to IEEE 754 double precision floating point, one cannot store 64 bit integers with full precision. Lua numbers are stored as floating point (doubles) internally, not integers; thus while they can represent incredibly large numbers, above 2^53 they lose integral precision -- they can't represent every whole integer value. For example if you set a lua variable to the number 9007199254740992 and tried to increment it by 1, you'd get the same number because it can't represent 9007199254740993 (only the even number 9007199254740994). @@ -39,9 +39,6 @@ either expressed or implied, of the FreeBSD Project. Note that comparison operators ('==','$$<=$$','>', etc.) will not work with plain numbers -- only other Int64/UInt64 objects. This is a limitation of Lua itself, in terms of how it handles operator overloading. - // Previous to Wireshark release 1.11, Int64 and UInt64 could only be created by tvbrange:int64() or tvbrange:le_int64(), or tvbrange:uint64() or tvbrange:le_uint64() or tvbrange:bitfield(), and had only a couple functions (the metamethods tostring() and concat()). - // All of the functions on this page are only available starting in Wireshark 1.11 and higher. - [WARNING] ==== Many of the UInt64/Int64 functions accept a Lua number as an argument. @@ -78,14 +75,24 @@ either expressed or implied, of the FreeBSD Project. -- Bad. Leads to inconsistent results across platforms local masked = mynum:band(0xFFFFFFFF00000000) ---- + + [NOTE] + ==== + Lua 5.3 and later adds a second number representation for integers, which is also chosen at compile time. It is usually a 64-bit signed integer type, even on 32-bit platforms. + (Lua 5.2 and earlier have an integer type, but this is not used for storing numbers, only for casting, and on 32-bit platforms is 32-bits wide.) + Wireshark 4.4 and later will use the Lua integer type where possible, but as storing + 64-bit unsigned integers in a Lua Integer can result in signed number overflow, `UInt64` + is still necessary. `Int64` is also still available for use. + ==== + */ #define LUATYPE64_STRING_SIZE 21 /* string to hold 18446744073709551615 */ #if G_BYTE_ORDER == G_LITTLE_ENDIAN -#define IS_LITTLE_ENDIAN TRUE +#define IS_LITTLE_ENDIAN true #else -#define IS_LITTLE_ENDIAN FALSE +#define IS_LITTLE_ENDIAN false #endif WSLUA_CLASS_DEFINE_BASE(Int64,NOP,0); @@ -95,15 +102,15 @@ WSLUA_CLASS_DEFINE_BASE(Int64,NOP,0); Note the caveats <<lua_module_Int64,listed above>>. */ -/* A checkInt64 but that also auto-converts numbers, strings, and UINT64 to a gint64 */ -static gint64 getInt64(lua_State *L, int i) +/* A checkInt64 but that also auto-converts numbers, strings, and UINT64 to a int64_t */ +static int64_t getInt64(lua_State *L, int i) { - gchar *end = NULL; + char *end = NULL; (void) end; switch (lua_type(L,i)) { case LUA_TNUMBER: - return wslua_checkgint64(L,i); + return wslua_checkint64(L,i); case LUA_TSTRING: return g_ascii_strtoll(luaL_checkstring(L,i),&end,10); case LUA_TUSERDATA: @@ -118,36 +125,34 @@ static gint64 getInt64(lua_State *L, int i) /* Encodes Int64 userdata into Lua string struct with given endianness */ -void Int64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian) { - gint64 value = checkInt64(L,idx); - gint8 buff[sizeof(gint64)]; +void Int64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian) { + int64_t value = checkInt64(L,idx); + int8_t buff[sizeof(int64_t)]; if (asLittleEndian) { - guint i; - for (i = 0; i < sizeof(gint64); i++) { + unsigned i; + for (i = 0; i < sizeof(int64_t); i++) { buff[i] = (value & 0xff); value >>= 8; } } else { - gint i; - for (i = sizeof(gint64) - 1; i >= 0; i--) { + int i; + for (i = sizeof(int64_t) - 1; i >= 0; i--) { buff[i] = (value & 0xff); value >>= 8; } } - luaL_addlstring(b, (char*)buff, sizeof(gint64)); + luaL_addlstring(b, (char*)buff, sizeof(int64_t)); } WSLUA_METHOD Int64_encode(lua_State* L) { - /* Encodes the <<lua_class_Int64,`Int64`>> number into an 8-byte Lua string using the given endianness. - @since 1.11.3 - */ + /* Encodes the <<lua_class_Int64,`Int64`>> number into an 8-byte Lua string using the given endianness. */ #define WSLUA_OPTARG_Int64_encode_ENDIAN 2 /* If set to true then little-endian is used, if false then big-endian; if missing or `nil`, native host endian. */ luaL_Buffer b; - gboolean asLittleEndian = IS_LITTLE_ENDIAN; + bool asLittleEndian = IS_LITTLE_ENDIAN; if (lua_gettop(L) >= WSLUA_OPTARG_Int64_encode_ENDIAN) { if (lua_type(L,WSLUA_OPTARG_Int64_encode_ENDIAN) == LUA_TBOOLEAN) @@ -163,20 +168,20 @@ WSLUA_METHOD Int64_encode(lua_State* L) { } /* Decodes from string buffer struct into Int64 userdata, with given endianness */ -int Int64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian) { - gint64 value = 0; - gint i; +int Int64_unpack(lua_State* L, const char *buff, bool asLittleEndian) { + int64_t value = 0; + int i; if (asLittleEndian) { - for (i = sizeof(gint64) - 1; i >= 0; i--) { + for (i = sizeof(int64_t) - 1; i >= 0; i--) { value <<= 8; - value |= (gint64)(guchar)buff[i]; + value |= (int64_t)(unsigned char)buff[i]; } } else { - for (i = 0; i < (gint) sizeof(gint64); i++) { + for (i = 0; i < (int) sizeof(int64_t); i++) { value <<= 8; - value |= (gint64)(guchar)buff[i]; + value |= (int64_t)(unsigned char)buff[i]; } } @@ -185,23 +190,21 @@ int Int64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian) { } WSLUA_CONSTRUCTOR Int64_decode(lua_State* L) { - /* Decodes an 8-byte Lua string, using the given endianness, into a new <<lua_class_Int64,`Int64`>> object. - @since 1.11.3 - */ + /* Decodes an 8-byte Lua string, using the given endianness, into a new <<lua_class_Int64,`Int64`>> object. */ #define WSLUA_ARG_Int64_decode_STRING 1 /* The Lua string containing a binary 64-bit integer. */ #define WSLUA_OPTARG_Int64_decode_ENDIAN 2 /* If set to true then little-endian is used, if false then big-endian; if missing or `nil`, native host endian. */ - gboolean asLittleEndian = IS_LITTLE_ENDIAN; + bool asLittleEndian = IS_LITTLE_ENDIAN; size_t len = 0; - const gchar *s = luaL_checklstring(L, WSLUA_ARG_Int64_decode_STRING, &len); + const char *s = luaL_checklstring(L, WSLUA_ARG_Int64_decode_STRING, &len); if (lua_gettop(L) >= WSLUA_OPTARG_Int64_decode_ENDIAN) { if (lua_type(L,WSLUA_OPTARG_Int64_decode_ENDIAN) == LUA_TBOOLEAN) asLittleEndian = lua_toboolean(L,WSLUA_OPTARG_Int64_decode_ENDIAN); } - if (len == sizeof(gint64)) { + if (len == sizeof(int64_t)) { Int64_unpack(L, s, asLittleEndian); } else { lua_pushnil(L); @@ -211,26 +214,24 @@ WSLUA_CONSTRUCTOR Int64_decode(lua_State* L) { } WSLUA_CONSTRUCTOR Int64_new(lua_State* L) { - /* Creates a <<lua_class_Int64,`Int64`>> Object. - @since 1.11.3 - */ + /* Creates a <<lua_class_Int64,`Int64`>> object. */ #define WSLUA_OPTARG_Int64_new_VALUE 1 /* A number, <<lua_class_UInt64,`UInt64`>>, <<lua_class_Int64,`Int64`>>, or string of ASCII digits to assign the value of the new <<lua_class_Int64,`Int64`>>. Default is 0. */ #define WSLUA_OPTARG_Int64_new_HIGHVALUE 2 /* If this is a number and the first argument was a number, then the first will be treated as a lower 32 bits, and this is the high-order 32 bit number. */ - gint64 value = 0; + int64_t value = 0; if (lua_gettop(L) >= 1) { switch(lua_type(L, WSLUA_OPTARG_Int64_new_VALUE)) { case LUA_TNUMBER: - value = wslua_togint64(L, WSLUA_OPTARG_Int64_new_VALUE); + value = wslua_toint64(L, WSLUA_OPTARG_Int64_new_VALUE); if (lua_gettop(L) == 2 && lua_type(L, WSLUA_OPTARG_Int64_new_HIGHVALUE) == LUA_TNUMBER) { - gint64 h = wslua_togint64(L, WSLUA_OPTARG_Int64_new_HIGHVALUE); - value &= G_GUINT64_CONSTANT(0x00000000FFFFFFFF); - h <<= 32; h &= G_GUINT64_CONSTANT(0xFFFFFFFF00000000); + int64_t h = wslua_toint64(L, WSLUA_OPTARG_Int64_new_HIGHVALUE); + value &= UINT64_C(0x00000000FFFFFFFF); + h <<= 32; h &= UINT64_C(0xFFFFFFFF00000000); value += h; } break; @@ -250,66 +251,54 @@ WSLUA_CONSTRUCTOR Int64_new(lua_State* L) { } WSLUA_METAMETHOD Int64__call(lua_State* L) { - /* Creates a <<lua_class_Int64,`Int64`>> object. - @since 1.11.3 - */ + /* Creates a <<lua_class_Int64,`Int64`>> object. */ lua_remove(L,1); /* remove the table */ WSLUA_RETURN(Int64_new(L)); /* The new <<lua_class_Int64,`Int64`>> object. */ } WSLUA_CONSTRUCTOR Int64_max(lua_State* L) { - /* Creates an <<lua_class_Int64,`Int64`>> of the maximum possible positive value. In other words, this should return an Int64 object of the number 9,223,372,036,854,775,807. - @since 1.11.3 - */ - pushInt64(L, G_MAXINT64); + /* Creates an <<lua_class_Int64,`Int64`>> of the maximum possible positive value. In other words, this should return an Int64 object of the number 9,223,372,036,854,775,807. */ + pushInt64(L, INT64_MAX); WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object of the maximum value. */ } WSLUA_CONSTRUCTOR Int64_min(lua_State* L) { - /* Creates an <<lua_class_Int64,`Int64`>> of the minimum possible negative value. In other words, this should return an Int64 object of the number -9,223,372,036,854,775,808. - @since 1.11.3 - */ - pushInt64(L, G_MININT64); + /* Creates an <<lua_class_Int64,`Int64`>> of the minimum possible negative value. In other words, this should return an Int64 object of the number -9,223,372,036,854,775,808. */ + pushInt64(L, INT64_MIN); WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object of the minimum value. */ } WSLUA_METHOD Int64_tonumber(lua_State* L) { - /* Returns a Lua number of the <<lua_class_Int64,`Int64`>> value. Note that this may lose precision. - @since 1.11.3 - */ + /* Returns a Lua number of the <<lua_class_Int64,`Int64`>> value. Note that this may lose precision. */ lua_pushnumber(L, (lua_Number)(checkInt64(L,1))); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_CONSTRUCTOR Int64_fromhex(lua_State* L) { - /* Creates an <<lua_class_Int64,`Int64`>> object from the given hexadecimal string. - @since 1.11.3 - */ + /* Creates an <<lua_class_Int64,`Int64`>> object from the given hexadecimal string. */ #define WSLUA_ARG_Int64_fromhex_HEX 1 /* The hex-ASCII Lua string. */ - guint64 result = 0; + uint64_t result = 0; size_t len = 0; - const gchar *s = luaL_checklstring(L,WSLUA_ARG_Int64_fromhex_HEX,&len); + const char *s = luaL_checklstring(L,WSLUA_ARG_Int64_fromhex_HEX,&len); if (len > 0) { if (sscanf(s, "%" SCNx64, &result) != 1) { return luaL_error(L, "Error decoding the passed-in hex string"); } } - pushInt64(L,(gint64)result); + pushInt64(L,(int64_t)result); WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_tohex(lua_State* L) { - /* Returns a hexadecimal string of the <<lua_class_Int64,`Int64`>> value. - @since 1.11.3 - */ + /* Returns a hexadecimal string of the <<lua_class_Int64,`Int64`>> value. */ #define WSLUA_OPTARG_Int64_tohex_NUMBYTES 2 /* The number of hex chars/nibbles to generate. A negative value generates uppercase. Default is 16. */ - gint64 b = getInt64(L,1); + int64_t b = getInt64(L,1); lua_Integer n = luaL_optinteger(L, WSLUA_OPTARG_Int64_tohex_NUMBYTES, 16); - const gchar *hexdigits = "0123456789abcdef"; - gchar buf[16]; + const char *hexdigits = "0123456789abcdef"; + char buf[16]; lua_Integer i; if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; } if (n > 16) n = 16; @@ -321,34 +310,31 @@ WSLUA_METHOD Int64_tohex(lua_State* L) { WSLUA_METHOD Int64_higher(lua_State* L) { /* Returns a Lua number of the higher 32 bits of the <<lua_class_Int64,`Int64`>> value. A negative <<lua_class_Int64,`Int64`>> will return a negative Lua number. - @since 1.11.3 */ - gint64 num = getInt64(L,1); - gint64 b = num; + int64_t num = getInt64(L,1); + int64_t b = num; lua_Number n = 0; if (b < 0) b = -b; /* masking/shifting negative int64 isn't working on some platforms */ - b &= G_GUINT64_CONSTANT(0x7FFFFFFF00000000); + b &= UINT64_C(0x7FFFFFFF00000000); b >>= 32; - n = (lua_Number)(guint32)(b & G_GUINT64_CONSTANT(0x00000000FFFFFFFFF)); + n = (lua_Number)(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF)); if (num < 0) n = -n; lua_pushnumber(L,n); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METHOD Int64_lower(lua_State* L) { - /* Returns a Lua number of the lower 32 bits of the <<lua_class_Int64,`Int64`>> value. This will always be positive. - @since 1.11.3 - */ - gint64 b = getInt64(L,1); + /* Returns a Lua number of the lower 32 bits of the <<lua_class_Int64,`Int64`>> value. This will always be positive. */ + int64_t b = getInt64(L,1); if (b < 0) b = -b; /* masking/shifting negative int64 isn't working on some platforms */ - lua_pushnumber(L,(guint32)(b & G_GUINT64_CONSTANT(0x00000000FFFFFFFFF))); + lua_pushnumber(L,(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF))); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METAMETHOD Int64__tostring(lua_State* L) { /* Converts the <<lua_class_Int64,`Int64`>> into a string of decimal digits. */ - gint64 num = getInt64(L,1); - gchar s[LUATYPE64_STRING_SIZE]; + int64_t num = getInt64(L,1); + char s[LUATYPE64_STRING_SIZE]; if (snprintf(s, LUATYPE64_STRING_SIZE, "%" PRId64, num) < 0) { return luaL_error(L, "Error writing Int64 to a string"); } @@ -357,9 +343,7 @@ WSLUA_METAMETHOD Int64__tostring(lua_State* L) { } WSLUA_METAMETHOD Int64__unm(lua_State* L) { - /* Returns the negative of the <<lua_class_Int64,`Int64`>> as a new <<lua_class_Int64,`Int64`>>. - @since 1.11.3 - */ + /* Returns the negative of the <<lua_class_Int64,`Int64`>> as a new <<lua_class_Int64,`Int64`>>. */ pushInt64(L,-(getInt64(L,1))); WSLUA_RETURN(1); /* The new <<lua_class_Int64,`Int64`>>. */ } @@ -372,30 +356,23 @@ WSLUA_METAMETHOD Int64__unm(lua_State* L) { return 1 WSLUA_METAMETHOD Int64__add(lua_State* L) { - /* Adds two <<lua_class_Int64,`Int64`>> together and returns a new one. The value may wrapped. - @since 1.11.3 - */ + /* Adds two <<lua_class_Int64,`Int64`>> together and returns a new one. The value may wrapped. */ WSLUA_MATH_OP_FUNC(Int64,+); } WSLUA_METAMETHOD Int64__sub(lua_State* L) { - /* Subtracts two <<lua_class_Int64,`Int64`>> and returns a new one. The value may wrapped. - @since 1.11.3 - */ + /* Subtracts two <<lua_class_Int64,`Int64`>> and returns a new one. The value may wrapped. */ WSLUA_MATH_OP_FUNC(Int64,-); } WSLUA_METAMETHOD Int64__mul(lua_State* L) { - /* Multiplies two <<lua_class_Int64,`Int64`>> and returns a new one. The value may truncated. - @since 1.11.3 - */ + /* Multiplies two <<lua_class_Int64,`Int64`>> and returns a new one. The value may truncated. */ WSLUA_MATH_OP_FUNC(Int64,*); } WSLUA_METAMETHOD Int64__div(lua_State* L) { /* Divides two <<lua_class_Int64,`Int64`>> and returns a new one. Integer divide, no remainder. Trying to divide by zero results in a Lua error. - @since 1.11.3 */ Int64 num1 = getInt64(L,1); Int64 num2 = getInt64(L,2); @@ -409,7 +386,6 @@ WSLUA_METAMETHOD Int64__div(lua_State* L) { WSLUA_METAMETHOD Int64__mod(lua_State* L) { /* Divides two <<lua_class_Int64,`Int64`>> and returns a new one of the remainder. Trying to modulo by zero results in a Lua error. - @since 1.11.3 */ Int64 num1 = getInt64(L,1); Int64 num2 = getInt64(L,2); @@ -423,13 +399,12 @@ WSLUA_METAMETHOD Int64__mod(lua_State* L) { WSLUA_METAMETHOD Int64__pow(lua_State* L) { /* The first <<lua_class_Int64,`Int64`>> is taken to the power of the second <<lua_class_Int64,`Int64`>>, returning a new one. This may truncate the value. - @since 1.11.3 */ - gint64 num1 = getInt64(L,1); - gint64 num2 = getInt64(L,2); - gint64 result; + int64_t num1 = getInt64(L,1); + int64_t num2 = getInt64(L,2); + int64_t result; if (num1 == 2) { - result = (num2 >= 8 * (gint64) sizeof(gint64)) ? 0 : ((gint64)1 << num2); + result = (num2 >= 8 * (int64_t) sizeof(int64_t)) ? 0 : ((int64_t)1 << num2); } else { for (result = 1; num2 > 0; num2 >>= 1) { @@ -448,36 +423,28 @@ WSLUA_METAMETHOD Int64__pow(lua_State* L) { return 1 WSLUA_METAMETHOD Int64__eq(lua_State* L) { - /* Returns `true` if both <<lua_class_Int64,`Int64`>> are equal. - @since 1.11.3 - */ + /* Returns `true` if both <<lua_class_Int64,`Int64`>> are equal. */ WSLUA_COMP_OP_FUNC(Int64,==); } WSLUA_METAMETHOD Int64__lt(lua_State* L) { - /* Returns `true` if first <<lua_class_Int64,`Int64`>> is less than the second. - @since 1.11.3 - */ + /* Returns `true` if first <<lua_class_Int64,`Int64`>> is less than the second. */ WSLUA_COMP_OP_FUNC(Int64,<); } WSLUA_METAMETHOD Int64__le(lua_State* L) { - /* Returns `true` if the first <<lua_class_Int64,`Int64`>> is less than or equal to the second. - @since 1.11.3 - */ + /* Returns `true` if the first <<lua_class_Int64,`Int64`>> is less than or equal to the second. */ WSLUA_COMP_OP_FUNC(Int64,<=); } WSLUA_METHOD Int64_bnot(lua_State* L) { - /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'not' operation. - @since 1.11.3 - */ + /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'not' operation. */ pushInt64(L,~(getInt64(L,1))); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } #define WSLUA_BIT_OP_FUNC(obj,op) \ - gint32 i; \ + int32_t i; \ obj num = get##obj(L,1); \ for (i = lua_gettop(L); i > 1; i--) { \ num op get##obj(L,i); \ @@ -488,7 +455,6 @@ WSLUA_METHOD Int64_bnot(lua_State* L) { WSLUA_METHOD Int64_band(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'and' operation with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(Int64,&=); } @@ -496,7 +462,6 @@ WSLUA_METHOD Int64_band(lua_State* L) { WSLUA_METHOD Int64_bor(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'or' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(Int64,|=); } @@ -504,7 +469,6 @@ WSLUA_METHOD Int64_bor(lua_State* L) { WSLUA_METHOD Int64_bxor(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise 'xor' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(Int64,^=); } @@ -512,35 +476,32 @@ WSLUA_METHOD Int64_bxor(lua_State* L) { WSLUA_METHOD Int64_lshift(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise logical left-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_Int64_lshift_NUMBITS 2 /* The number of bits to left-shift by. */ - guint64 b = (guint64) getInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_lshift_NUMBITS); - pushInt64(L,(gint64)(b << n)); + uint64_t b = (uint64_t) getInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_lshift_NUMBITS); + pushInt64(L,(int64_t)(b << n)); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_rshift(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise logical right-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_Int64_rshift_NUMBITS 2 /* The number of bits to right-shift by. */ - guint64 b = (guint64) getInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_rshift_NUMBITS); - pushInt64(L,(gint64)(b >> n)); + uint64_t b = (uint64_t) getInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_rshift_NUMBITS); + pushInt64(L,(int64_t)(b >> n)); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_arshift(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise arithmetic right-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_Int64_arshift_NUMBITS 2 /* The number of bits to right-shift by. */ - gint64 b = getInt64(L,1); - gint32 n = wslua_checkgint32(L,WSLUA_ARG_Int64_arshift_NUMBITS); + int64_t b = getInt64(L,1); + int32_t n = wslua_checkint32(L,WSLUA_ARG_Int64_arshift_NUMBITS); pushInt64(L,(b >> n)); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } @@ -548,41 +509,38 @@ WSLUA_METHOD Int64_arshift(lua_State* L) { WSLUA_METHOD Int64_rol(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise left rotation operation, by the given number of bits (up to 63). - @since 1.11.3 */ #define WSLUA_ARG_Int64_rol_NUMBITS 2 /* The number of bits to roll left by. */ - guint64 b = (guint64) getInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_rol_NUMBITS); - pushInt64(L,(gint64)((b << n) | (b >> (64-n)))); + uint64_t b = (uint64_t) getInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_rol_NUMBITS); + pushInt64(L,(int64_t)((b << n) | (b >> (64-n)))); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_ror(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bitwise right rotation operation, by the given number of bits (up to 63). - @since 1.11.3 */ #define WSLUA_ARG_Int64_ror_NUMBITS 2 /* The number of bits to roll right by. */ - guint64 b = (guint64) getInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_Int64_ror_NUMBITS); - pushInt64(L,(gint64)((b << (64-n)) | (b >> n))); + uint64_t b = (uint64_t) getInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_Int64_ror_NUMBITS); + pushInt64(L,(int64_t)((b << (64-n)) | (b >> n))); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } WSLUA_METHOD Int64_bswap(lua_State* L) { /* Returns a <<lua_class_Int64,`Int64`>> of the bytes swapped. This can be used to convert little-endian 64-bit numbers to big-endian 64 bit numbers or vice versa. - @since 1.11.3 */ - guint64 b = (guint64) getInt64(L,1); - guint64 result = 0; + uint64_t b = (uint64_t) getInt64(L,1); + uint64_t result = 0; size_t i; - for (i = 0; i < sizeof(gint64); i++) { + for (i = 0; i < sizeof(int64_t); i++) { result <<= 8; - result |= (b & G_GUINT64_CONSTANT(0x00000000000000FF)); + result |= (b & UINT64_C(0x00000000000000FF)); b >>= 8; } - pushInt64(L,(gint64)result); + pushInt64(L,(int64_t)result); WSLUA_RETURN(1); /* The <<lua_class_Int64,`Int64`>> object. */ } @@ -646,15 +604,15 @@ WSLUA_CLASS_DEFINE_BASE(UInt64,NOP,0); Note the caveats <<lua_module_Int64,listed above>>. */ -/* A checkUInt64 but that also auto-converts numbers, strings, and <<lua_class_Int64,`Int64`>> to a guint64. */ -guint64 getUInt64(lua_State *L, int i) +/* A checkUInt64 but that also auto-converts numbers, strings, and <<lua_class_Int64,`Int64`>> to a uint64_t. */ +uint64_t getUInt64(lua_State *L, int i) { - gchar *end = NULL; + char *end = NULL; (void) end; switch (lua_type(L,i)) { case LUA_TNUMBER: - return wslua_checkguint64(L,i); + return wslua_checkuint64(L,i); case LUA_TSTRING: return g_ascii_strtoull(luaL_checkstring(L,i), &end, 0); case LUA_TUSERDATA: @@ -668,36 +626,34 @@ guint64 getUInt64(lua_State *L, int i) } /* Encodes <<lua_class_UInt64,`UInt64`>> userdata into Lua string struct with given endianness */ -void UInt64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian) { - guint64 value = checkUInt64(L,idx); - gint8 buff[sizeof(guint64)]; +void UInt64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian) { + uint64_t value = checkUInt64(L,idx); + int8_t buff[sizeof(uint64_t)]; if (asLittleEndian) { - guint i; - for (i = 0; i < sizeof(guint64); i++) { + unsigned i; + for (i = 0; i < sizeof(uint64_t); i++) { buff[i] = (value & 0xff); value >>= 8; } } else { - gint i; - for (i = sizeof(guint64) - 1; i >= 0; i--) { + int i; + for (i = sizeof(uint64_t) - 1; i >= 0; i--) { buff[i] = (value & 0xff); value >>= 8; } } - luaL_addlstring(b, (char*)buff, sizeof(guint64)); + luaL_addlstring(b, (char*)buff, sizeof(uint64_t)); } WSLUA_METHOD UInt64_encode(lua_State* L) { - /* Encodes the <<lua_class_UInt64,`UInt64`>> number into an 8-byte Lua binary string, using given endianness. - @since 1.11.3 - */ + /* Encodes the <<lua_class_UInt64,`UInt64`>> number into an 8-byte Lua binary string, using given endianness. */ #define WSLUA_OPTARG_UInt64_encode_ENDIAN 2 /* If set to true then little-endian is used, if false then big-endian; if missing or `nil`, native host endian. */ luaL_Buffer b; - gboolean asLittleEndian = IS_LITTLE_ENDIAN; + bool asLittleEndian = IS_LITTLE_ENDIAN; if (lua_gettop(L) >= 2) { if (lua_type(L,2) == LUA_TBOOLEAN) @@ -713,20 +669,20 @@ WSLUA_METHOD UInt64_encode(lua_State* L) { } /* Decodes from string buffer struct into <<lua_class_UInt64,`UInt64`>> userdata, with given endianness. */ -int UInt64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian) { - guint64 value = 0; - gint i; +int UInt64_unpack(lua_State* L, const char *buff, bool asLittleEndian) { + uint64_t value = 0; + int i; if (asLittleEndian) { - for (i = sizeof(guint64) - 1; i >= 0; i--) { + for (i = sizeof(uint64_t) - 1; i >= 0; i--) { value <<= 8; - value |= (guint64)(guchar)buff[i]; + value |= (uint64_t)(unsigned char)buff[i]; } } else { - for (i = 0; i < (gint) sizeof(guint64); i++) { + for (i = 0; i < (int) sizeof(uint64_t); i++) { value <<= 8; - value |= (guint64)(guchar)buff[i]; + value |= (uint64_t)(unsigned char)buff[i]; } } @@ -735,23 +691,21 @@ int UInt64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian) { } WSLUA_CONSTRUCTOR UInt64_decode(lua_State* L) { - /* Decodes an 8-byte Lua binary string, using given endianness, into a new <<lua_class_UInt64,`UInt64`>> object. - @since 1.11.3 - */ + /* Decodes an 8-byte Lua binary string, using given endianness, into a new <<lua_class_UInt64,`UInt64`>> object. */ #define WSLUA_ARG_UInt64_decode_STRING 1 /* The Lua string containing a binary 64-bit integer. */ #define WSLUA_OPTARG_UInt64_decode_ENDIAN 2 /* If set to true then little-endian is used, if false then big-endian; if missing or `nil`, native host endian. */ - gboolean asLittleEndian = IS_LITTLE_ENDIAN; + bool asLittleEndian = IS_LITTLE_ENDIAN; size_t len = 0; - const gchar *s = luaL_checklstring(L, WSLUA_ARG_UInt64_decode_STRING, &len); + const char *s = luaL_checklstring(L, WSLUA_ARG_UInt64_decode_STRING, &len); if (lua_gettop(L) >= WSLUA_OPTARG_UInt64_decode_ENDIAN) { if (lua_type(L,WSLUA_OPTARG_UInt64_decode_ENDIAN) == LUA_TBOOLEAN) asLittleEndian = lua_toboolean(L,WSLUA_OPTARG_UInt64_decode_ENDIAN); } - if (len == sizeof(guint64)) { + if (len == sizeof(uint64_t)) { UInt64_unpack(L, s, asLittleEndian); } else { lua_pushnil(L); @@ -761,26 +715,24 @@ WSLUA_CONSTRUCTOR UInt64_decode(lua_State* L) { } WSLUA_CONSTRUCTOR UInt64_new(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> Object. - @since 1.11.3 - */ + /* Creates a <<lua_class_UInt64,`UInt64`>> object. */ #define WSLUA_OPTARG_UInt64_new_VALUE 1 /* A number, <<lua_class_UInt64,`UInt64`>>, <<lua_class_Int64,`Int64`>>, or string of digits to assign the value of the new <<lua_class_UInt64,`UInt64`>>. Default is 0. */ #define WSLUA_OPTARG_UInt64_new_HIGHVALUE 2 /* If this is a number and the first argument was a number, then the first will be treated as a lower 32 bits, and this is the high-order 32-bit number. */ - guint64 value = 0; + uint64_t value = 0; if (lua_gettop(L) >= 1) { switch(lua_type(L, WSLUA_OPTARG_UInt64_new_VALUE)) { case LUA_TNUMBER: - value = wslua_toguint64(L, WSLUA_OPTARG_UInt64_new_VALUE); + value = wslua_touint64(L, WSLUA_OPTARG_UInt64_new_VALUE); if (lua_gettop(L) == 2 && lua_type(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE) == LUA_TNUMBER) { - guint64 h = wslua_toguint64(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE); - value &= G_GUINT64_CONSTANT(0x00000000FFFFFFFF); - h <<= 32; h &= G_GUINT64_CONSTANT(0xFFFFFFFF00000000); + uint64_t h = wslua_touint64(L, WSLUA_OPTARG_UInt64_new_HIGHVALUE); + value &= UINT64_C(0x00000000FFFFFFFF); + h <<= 32; h &= UINT64_C(0xFFFFFFFF00000000); value += h; } break; @@ -800,42 +752,34 @@ WSLUA_CONSTRUCTOR UInt64_new(lua_State* L) { } WSLUA_METAMETHOD UInt64__call(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> object. - @since 1.11.3 - */ + /* Creates a <<lua_class_UInt64,`UInt64`>> object. */ lua_remove(L,1); /* remove the table */ WSLUA_RETURN(UInt64_new(L)); /* The new <<lua_class_UInt64,`UInt64`>> object. */ } WSLUA_CONSTRUCTOR UInt64_max(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> of the maximum possible value. In other words, this should return an UInt64 object of the number 18,446,744,073,709,551,615. - @since 1.11.3 - */ - pushUInt64(L,G_MAXUINT64); + /* Creates a <<lua_class_UInt64,`UInt64`>> of the maximum possible value. In other words, this should return an UInt64 object of the number 18,446,744,073,709,551,615. */ + pushUInt64(L,UINT64_MAX); WSLUA_RETURN(1); /* The maximum value. */ } WSLUA_CONSTRUCTOR UInt64_min(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> of the minimum possible value. In other words, this should return an UInt64 object of the number 0. - @since 1.11.3 - */ + /* Creates a <<lua_class_UInt64,`UInt64`>> of the minimum possible value. In other words, this should return an UInt64 object of the number 0. */ pushUInt64(L,0); WSLUA_RETURN(1); /* The minimum value. */ } WSLUA_METHOD UInt64_tonumber(lua_State* L) { - /* Returns a Lua number of the <<lua_class_UInt64,`UInt64`>> value. This may lose precision. - @since 1.11.3 - */ + /* Returns a Lua number of the <<lua_class_UInt64,`UInt64`>> value. This may lose precision. */ lua_pushnumber(L,(lua_Number)(checkUInt64(L,1))); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METAMETHOD UInt64__tostring(lua_State* L) { /* Converts the <<lua_class_UInt64,`UInt64`>> into a string. */ - guint64 num = getUInt64(L,1); - gchar s[LUATYPE64_STRING_SIZE]; - if (snprintf(s, LUATYPE64_STRING_SIZE, "%" PRIu64,(guint64)num) < 0) { + uint64_t num = getUInt64(L,1); + char s[LUATYPE64_STRING_SIZE]; + if (snprintf(s, LUATYPE64_STRING_SIZE, "%" PRIu64,(uint64_t)num) < 0) { return luaL_error(L, "Error writing UInt64 to a string"); } lua_pushstring(L,s); @@ -843,13 +787,11 @@ WSLUA_METAMETHOD UInt64__tostring(lua_State* L) { } WSLUA_CONSTRUCTOR UInt64_fromhex(lua_State* L) { - /* Creates a <<lua_class_UInt64,`UInt64`>> object from the given hex string. - @since 1.11.3 - */ + /* Creates a <<lua_class_UInt64,`UInt64`>> object from the given hex string. */ #define WSLUA_ARG_UInt64_fromhex_HEX 1 /* The hex-ASCII Lua string. */ - guint64 result = 0; + uint64_t result = 0; size_t len = 0; - const gchar *s = luaL_checklstring(L,WSLUA_ARG_UInt64_fromhex_HEX,&len); + const char *s = luaL_checklstring(L,WSLUA_ARG_UInt64_fromhex_HEX,&len); if (len > 0) { if (sscanf(s, "%" SCNx64, &result) != 1) { @@ -861,15 +803,13 @@ WSLUA_CONSTRUCTOR UInt64_fromhex(lua_State* L) { } WSLUA_METHOD UInt64_tohex(lua_State* L) { - /* Returns a hex string of the <<lua_class_UInt64,`UInt64`>> value. - @since 1.11.3 - */ + /* Returns a hex string of the <<lua_class_UInt64,`UInt64`>> value. */ #define WSLUA_OPTARG_UInt64_tohex_NUMBYTES 2 /* The number of hex-chars/nibbles to generate. Negative means uppercase Default is 16. */ - guint64 b = getUInt64(L,1); + uint64_t b = getUInt64(L,1); lua_Integer n = luaL_optinteger(L, WSLUA_OPTARG_UInt64_tohex_NUMBYTES, 16); - const gchar *hexdigits = "0123456789abcdef"; - gchar buf[16]; + const char *hexdigits = "0123456789abcdef"; + char buf[16]; lua_Integer i; if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; } if (n > 16) n = 16; @@ -880,56 +820,47 @@ WSLUA_METHOD UInt64_tohex(lua_State* L) { WSLUA_METHOD UInt64_higher(lua_State* L) { /* Returns a Lua number of the higher 32 bits of the <<lua_class_UInt64,`UInt64`>> value. */ - guint64 num = getUInt64(L,1); - guint64 b = num; + uint64_t num = getUInt64(L,1); + uint64_t b = num; lua_Number n = 0; - b &= G_GUINT64_CONSTANT(0xFFFFFFFF00000000); + b &= UINT64_C(0xFFFFFFFF00000000); b >>= 32; - n = (lua_Number)(guint32)(b & G_GUINT64_CONSTANT(0x00000000FFFFFFFFF)); + n = (lua_Number)(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF)); lua_pushnumber(L,n); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METHOD UInt64_lower(lua_State* L) { /* Returns a Lua number of the lower 32 bits of the <<lua_class_UInt64,`UInt64`>> value. */ - guint64 b = getUInt64(L,1); - lua_pushnumber(L,(guint32)(b & G_GUINT64_CONSTANT(0x00000000FFFFFFFFF))); + uint64_t b = getUInt64(L,1); + lua_pushnumber(L,(uint32_t)(b & UINT64_C(0x00000000FFFFFFFFF))); WSLUA_RETURN(1); /* The Lua number. */ } WSLUA_METAMETHOD UInt64__unm(lua_State* L) { - /* Returns the <<lua_class_UInt64,`UInt64`>> in a new <<lua_class_UInt64,`UInt64`>>, since unsigned integers can't be negated. - @since 1.11.3 - */ + /* Returns the <<lua_class_UInt64,`UInt64`>> in a new <<lua_class_UInt64,`UInt64`>>, since unsigned integers can't be negated. */ pushUInt64(L,getUInt64(L,1)); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } WSLUA_METAMETHOD UInt64__add(lua_State* L) { - /* Adds two <<lua_class_UInt64,`UInt64`>> together and returns a new one. This may wrap the value. - @since 1.11.3 - */ + /* Adds two <<lua_class_UInt64,`UInt64`>> together and returns a new one. This may wrap the value. */ WSLUA_MATH_OP_FUNC(UInt64,+); } WSLUA_METAMETHOD UInt64__sub(lua_State* L) { - /* Subtracts two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may wrap the value. - @since 1.11.3 - */ + /* Subtracts two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may wrap the value. */ WSLUA_MATH_OP_FUNC(UInt64,-); } WSLUA_METAMETHOD UInt64__mul(lua_State* L) { - /* Multiplies two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may truncate the value. - @since 1.11.3 - */ + /* Multiplies two <<lua_class_UInt64,`UInt64`>> and returns a new one. This may truncate the value. */ WSLUA_MATH_OP_FUNC(UInt64,*); } WSLUA_METAMETHOD UInt64__div(lua_State* L) { /* Divides two <<lua_class_UInt64,`UInt64`>> and returns a new one. Integer divide, no remainder. Trying to divide by zero results in a Lua error. - @since 1.11.3 */ UInt64 num1 = getUInt64(L,1); UInt64 num2 = getUInt64(L,2); @@ -943,7 +874,6 @@ WSLUA_METAMETHOD UInt64__div(lua_State* L) { WSLUA_METAMETHOD UInt64__mod(lua_State* L) { /* Divides two <<lua_class_UInt64,`UInt64`>> and returns a new one of the remainder. Trying to modulo by zero results in a Lua error. - @since 1.11.3 */ UInt64 num1 = getUInt64(L,1); UInt64 num2 = getUInt64(L,2); @@ -957,13 +887,12 @@ WSLUA_METAMETHOD UInt64__mod(lua_State* L) { WSLUA_METAMETHOD UInt64__pow(lua_State* L) { /* The first <<lua_class_UInt64,`UInt64`>> is taken to the power of the second <<lua_class_UInt64,`UInt64`>>/number, returning a new one. This may truncate the value. - @since 1.11.3 */ - guint64 num1 = getUInt64(L,1); - guint64 num2 = getUInt64(L,2); - guint64 result; + uint64_t num1 = getUInt64(L,1); + uint64_t num2 = getUInt64(L,2); + uint64_t result; if (num1 == 2) { - result = (num2 >= 8 * (guint64) sizeof(guint64)) ? 0 : ((guint64)1 << num2); + result = (num2 >= 8 * (uint64_t) sizeof(uint64_t)) ? 0 : ((uint64_t)1 << num2); } else { for (result = 1; num2 > 0; num2 >>= 1) { @@ -976,30 +905,22 @@ WSLUA_METAMETHOD UInt64__pow(lua_State* L) { } WSLUA_METAMETHOD UInt64__eq(lua_State* L) { - /* Returns true if both <<lua_class_UInt64,`UInt64`>> are equal. - @since 1.11.3 - */ + /* Returns true if both <<lua_class_UInt64,`UInt64`>> are equal. */ WSLUA_COMP_OP_FUNC(UInt64,==); } WSLUA_METAMETHOD UInt64__lt(lua_State* L) { - /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than the second. - @since 1.11.3 - */ + /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than the second. */ WSLUA_COMP_OP_FUNC(UInt64,<); } WSLUA_METAMETHOD UInt64__le(lua_State* L) { - /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than or equal to the second. - @since 1.11.3 - */ + /* Returns true if first <<lua_class_UInt64,`UInt64`>> is less than or equal to the second. */ WSLUA_COMP_OP_FUNC(UInt64,<=); } WSLUA_METHOD UInt64_bnot(lua_State* L) { - /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'not' operation. - @since 1.11.3 - */ + /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'not' operation. */ pushUInt64(L,~(getUInt64(L,1))); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1007,7 +928,6 @@ WSLUA_METHOD UInt64_bnot(lua_State* L) { WSLUA_METHOD UInt64_band(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'and' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(UInt64,&=); } @@ -1015,7 +935,6 @@ WSLUA_METHOD UInt64_band(lua_State* L) { WSLUA_METHOD UInt64_bor(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'or' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(UInt64,|=); } @@ -1023,7 +942,6 @@ WSLUA_METHOD UInt64_bor(lua_State* L) { WSLUA_METHOD UInt64_bxor(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise 'xor' operation, with the given number/`Int64`/`UInt64`. Note that multiple arguments are allowed. - @since 1.11.3 */ WSLUA_BIT_OP_FUNC(UInt64,^=); } @@ -1031,11 +949,10 @@ WSLUA_METHOD UInt64_bxor(lua_State* L) { WSLUA_METHOD UInt64_lshift(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise logical left-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_UInt64_lshift_NUMBITS 2 /* The number of bits to left-shift by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_lshift_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_lshift_NUMBITS); pushUInt64(L,(b << n)); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1043,11 +960,10 @@ WSLUA_METHOD UInt64_lshift(lua_State* L) { WSLUA_METHOD UInt64_rshift(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise logical right-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_UInt64_rshift_NUMBITS 2 /* The number of bits to right-shift by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_rshift_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_rshift_NUMBITS); pushUInt64(L,(b >> n)); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1055,11 +971,10 @@ WSLUA_METHOD UInt64_rshift(lua_State* L) { WSLUA_METHOD UInt64_arshift(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise arithmetic right-shift operation, by the given number of bits. - @since 1.11.3 */ #define WSLUA_ARG_UInt64_arshift_NUMBITS 2 /* The number of bits to right-shift by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_arshift_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_arshift_NUMBITS); pushUInt64(L,(b >> n)); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1067,11 +982,10 @@ WSLUA_METHOD UInt64_arshift(lua_State* L) { WSLUA_METHOD UInt64_rol(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise left rotation operation, by the given number of bits (up to 63). - @since 1.11.3 */ #define WSLUA_ARG_UInt64_rol_NUMBITS 2 /* The number of bits to roll left by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_rol_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_rol_NUMBITS); pushUInt64(L,((b << n) | (b >> (64-n)))); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1079,11 +993,10 @@ WSLUA_METHOD UInt64_rol(lua_State* L) { WSLUA_METHOD UInt64_ror(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bitwise right rotation operation, by the given number of bits (up to 63). - @since 1.11.3 */ #define WSLUA_ARG_UInt64_ror_NUMBITS 2 /* The number of bits to roll right by. */ - guint64 b = getUInt64(L,1); - guint32 n = wslua_checkguint32(L,WSLUA_ARG_UInt64_ror_NUMBITS); + uint64_t b = getUInt64(L,1); + uint32_t n = wslua_checkuint32(L,WSLUA_ARG_UInt64_ror_NUMBITS); pushUInt64(L,((b << (64-n)) | (b >> n))); WSLUA_RETURN(1); /* The <<lua_class_UInt64,`UInt64`>> object. */ } @@ -1091,14 +1004,13 @@ WSLUA_METHOD UInt64_ror(lua_State* L) { WSLUA_METHOD UInt64_bswap(lua_State* L) { /* Returns a <<lua_class_UInt64,`UInt64`>> of the bytes swapped. This can be used to convert little-endian 64-bit numbers to big-endian 64 bit numbers or vice versa. - @since 1.11.3 */ - guint64 b = getUInt64(L,1); - guint64 result = 0; + uint64_t b = getUInt64(L,1); + uint64_t result = 0; size_t i; - for (i = 0; i < sizeof(guint64); i++) { + for (i = 0; i < sizeof(uint64_t); i++) { result <<= 8; - result |= (b & G_GUINT64_CONSTANT(0x00000000000000FF)); + result |= (b & UINT64_C(0x00000000000000FF)); b >>= 8; } pushUInt64(L,result); diff --git a/epan/wslua/wslua_internals.c b/epan/wslua/wslua_internals.c index 186d6fa5..1b25aaed 100644 --- a/epan/wslua/wslua_internals.c +++ b/epan/wslua/wslua_internals.c @@ -15,6 +15,7 @@ */ #include "config.h" +#define WS_LOG_DOMAIN LOG_DOMAIN_WSLUA #include "wslua.h" #include <stdio.h> @@ -23,16 +24,6 @@ * (and the "wslua global" test). Enable by setting WSLUA_WITH_INTROSPECTION */ #define WSLUA_WITH_INTROSPECTION -#if LUA_VERSION_NUM == 501 -/* Compatibility with Lua 5.1, function was added in 5.2 */ -static -int lua_absindex(lua_State *L, int idx) { - return (idx > 0 || idx <= LUA_REGISTRYINDEX) - ? idx - : lua_gettop(L) + 1 + idx; -} -#endif - WSLUA_API int wslua__concat(lua_State* L) { /* Concatenate two objects to a string */ if (!luaL_callmeta(L,1,"__tostring")) @@ -49,15 +40,15 @@ WSLUA_API int wslua__concat(lua_State* L) { note that normal lua_toboolean returns 1 for any Lua value different from false and nil; otherwise it returns 0. So a string would give a 0, as would a number of 1. This function errors if the arg is a string, and sets the boolean to 1 for any - number other than 0. Like toboolean, this returns FALSE if the arg was missing. */ -WSLUA_API gboolean wslua_toboolean(lua_State* L, int n) { - gboolean val = FALSE; + number other than 0. Like toboolean, this returns false if the arg was missing. */ +WSLUA_API bool wslua_toboolean(lua_State* L, int n) { + bool val = false; if ( lua_isboolean(L,n) || lua_isnil(L,n) || lua_gettop(L) < n ) { val = lua_toboolean(L,n); } else if ( lua_type(L,n) == LUA_TNUMBER ) { int num = (int)luaL_checkinteger(L,n); - val = num != 0 ? TRUE : FALSE; + val = num != 0 ? true : false; } else { luaL_argerror(L,n,"must be a boolean or number"); } @@ -66,17 +57,17 @@ WSLUA_API gboolean wslua_toboolean(lua_State* L, int n) { } /* like luaL_checkinteger, except for booleans - this does not coerce other types */ -WSLUA_API gboolean wslua_checkboolean(lua_State* L, int n) { +WSLUA_API bool wslua_checkboolean(lua_State* L, int n) { if (!lua_isboolean(L,n) ) { luaL_argerror(L,n,"must be a boolean"); } - return lua_toboolean(L,n);; + return lua_toboolean(L,n); } -WSLUA_API gboolean wslua_optbool(lua_State* L, int n, gboolean def) { - gboolean val = FALSE; +WSLUA_API bool wslua_optbool(lua_State* L, int n, bool def) { + bool val = false; if ( lua_isboolean(L,n) ) { val = lua_toboolean(L,n); @@ -185,9 +176,9 @@ WSLUA_API void wslua_print_stack(char* s, lua_State* L) { /* C-code function equivalent of the typeof() function we created in Lua. * The Lua one is for Lua scripts to use, this one is for C-code to use. */ -const gchar* wslua_typeof_unknown = "UNKNOWN"; -const gchar* wslua_typeof(lua_State *L, int idx) { - const gchar *classname = wslua_typeof_unknown; +const char* wslua_typeof_unknown = "UNKNOWN"; +const char* wslua_typeof(lua_State *L, int idx) { + const char *classname = wslua_typeof_unknown; /* we'll try getting the class name for error reporting*/ if (luaL_getmetafield(L, idx, WSLUA_TYPEOF_FIELD)) { classname = luaL_optstring(L, -1, wslua_typeof_unknown); @@ -205,12 +196,12 @@ const gchar* wslua_typeof(lua_State *L, int idx) { * location idx. If it does not get a table, it pops whatever it got * and returns false. */ -gboolean wslua_get_table(lua_State *L, int idx, const gchar *name) { - gboolean result = TRUE; +bool wslua_get_table(lua_State *L, int idx, const char *name) { + bool result = true; lua_rawgetfield(L, idx, name); if (!lua_istable(L,-1)) { lua_pop(L,1); - result = FALSE; + result = false; } return result; } @@ -219,12 +210,12 @@ gboolean wslua_get_table(lua_State *L, int idx, const gchar *name) { * location idx. If it does not get a field, it pops whatever it got * and returns false. */ -gboolean wslua_get_field(lua_State *L, int idx, const gchar *name) { - gboolean result = TRUE; +bool wslua_get_field(lua_State *L, int idx, const char *name) { + bool result = true; lua_rawgetfield(L, idx, name); if (lua_isnil(L,-1)) { lua_pop(L,1); - result = FALSE; + result = false; } return result; } @@ -251,7 +242,7 @@ static int wslua_classmeta_index(lua_State *L) { * Getters are invoked with the table as parameter. Setters are invoked with the * table and the value as parameter. */ -static int wslua_instancemeta_index_impl(lua_State *L, gboolean is_getter) +static int wslua_instancemeta_index_impl(lua_State *L, bool is_getter) { const char *fieldname = luaL_checkstring(L, 2); const int attr_idx = lua_upvalueindex(2); @@ -298,18 +289,18 @@ static int wslua_instancemeta_index_impl(lua_State *L, gboolean is_getter) static int wslua_instancemeta_index(lua_State *L) { - return wslua_instancemeta_index_impl(L, TRUE); + return wslua_instancemeta_index_impl(L, true); } static int wslua_instancemeta_newindex(lua_State *L) { - return wslua_instancemeta_index_impl(L, FALSE); + return wslua_instancemeta_index_impl(L, false); } /* Pushes a hex string of the binary data argument. */ -int wslua_bin2hex(lua_State* L, const guint8* data, const guint len, const gboolean lowercase, const gchar* sep) { +int wslua_bin2hex(lua_State* L, const uint8_t* data, const unsigned len, const bool lowercase, const char* sep) { luaL_Buffer b; - guint i = 0; + unsigned i = 0; static const char byte_to_str_upper[256][3] = { "00","01","02","03","04","05","06","07","08","09","0A","0B","0C","0D","0E","0F", "10","11","12","13","14","15","16","17","18","19","1A","1B","1C","1D","1E","1F", @@ -347,7 +338,7 @@ int wslua_bin2hex(lua_State* L, const guint8* data, const guint len, const gbool "f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff" }; const char (*byte_to_str)[3] = byte_to_str_upper; - const guint last = len - 1; + const unsigned last = len - 1; if (lowercase) byte_to_str = byte_to_str_lower; @@ -364,13 +355,13 @@ int wslua_bin2hex(lua_State* L, const guint8* data, const guint len, const gbool } /* Pushes a binary string of the hex-ascii data argument. */ -int wslua_hex2bin(lua_State* L, const char* data, const guint len, const gchar* sep) { +int wslua_hex2bin(lua_State* L, const char* data, const unsigned len, const char* sep) { luaL_Buffer b; - guint i = 0; - guint seplen = 0; - gint8 c, d; + unsigned i = 0; + unsigned seplen = 0; + int8_t c, d; - static const gint8 str_to_nibble[256] = { + static const int8_t str_to_nibble[256] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, @@ -389,12 +380,12 @@ int wslua_hex2bin(lua_State* L, const char* data, const guint len, const gchar* -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 }; - if (sep) seplen = (guint) strlen(sep); + if (sep) seplen = (unsigned) strlen(sep); luaL_buffinit(L, &b); for (i = 0; i < len;) { - c = str_to_nibble[(guchar)data[i]]; + c = str_to_nibble[(unsigned char)data[i]]; if (c < 0) { if (seplen && strncmp(&data[i], sep, seplen) == 0) { i += seplen; @@ -403,7 +394,7 @@ int wslua_hex2bin(lua_State* L, const char* data, const guint len, const gchar* break; } } - d = str_to_nibble[(guchar)data[++i]]; + d = str_to_nibble[(unsigned char)data[++i]]; if (d < 0) break; luaL_addchar(&b, (c * 16) + d); i++; @@ -420,7 +411,7 @@ int wslua_hex2bin(lua_State* L, const char* data, const guint len, const gchar* * Additionally, a sanity check is performed to detect colliding getters/setters * and method names. */ -static void wslua_push_attributes(lua_State *L, const wslua_attribute_table *t, gboolean is_getter, int methods_idx) +static void wslua_push_attributes(lua_State *L, const wslua_attribute_table *t, bool is_getter, int methods_idx) { if (!t) { /* No property accessors? Nothing to do. */ @@ -429,7 +420,7 @@ static void wslua_push_attributes(lua_State *L, const wslua_attribute_table *t, return; } - /* If there is a methods table, prepare for a collission check. */ + /* If there is a methods table, prepare for a collision check. */ if (lua_istable(L, methods_idx)) { methods_idx = lua_absindex(L, methods_idx); } else { @@ -482,7 +473,7 @@ void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def) /* Prepare __index method on metatable. */ lua_pushstring(L, cls_def->name); /* upval 1: class name */ - wslua_push_attributes(L, cls_def->attrs, TRUE, -2); /* upval 2: getters table */ + wslua_push_attributes(L, cls_def->attrs, true, -2); /* upval 2: getters table */ #ifdef WSLUA_WITH_INTROSPECTION lua_pushvalue(L, -1); lua_rawsetfield(L, -5, "__getters"); /* set (transition) property on mt, remove later! */ @@ -494,7 +485,7 @@ void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def) /* Prepare __newindex method on metatable. */ lua_pushstring(L, cls_def->name); /* upval 1: class name */ - wslua_push_attributes(L, cls_def->attrs, FALSE, -2); /* upval 2: setters table */ + wslua_push_attributes(L, cls_def->attrs, false, -2); /* upval 2: setters table */ #ifdef WSLUA_WITH_INTROSPECTION lua_pushvalue(L, -1); lua_rawsetfield(L, -5, "__setters"); /* set (transition) property on mt, remove later! */ diff --git a/epan/wslua/wslua_listener.c b/epan/wslua/wslua_listener.c index 669a64f9..156ff690 100644 --- a/epan/wslua/wslua_listener.c +++ b/epan/wslua/wslua_listener.c @@ -15,6 +15,7 @@ */ #include "config.h" +#define WS_LOG_DOMAIN LOG_DOMAIN_WSLUA /* WSLUA_MODULE Listener Post-Dissection Packet Analysis */ @@ -27,11 +28,11 @@ WSLUA_CLASS_DEFINE(Listener,FAIL_ON_NULL("Listener")); */ static int tap_packet_cb_error_handler(lua_State* L) { - const gchar* error = lua_tostring(L,1); - static gchar* last_error = NULL; + const char* error = lua_tostring(L,1); + static char* last_error = NULL; static int repeated = 0; static int next = 2; - gchar* where = (lua_pinfo) ? + char* where = (lua_pinfo) ? wmem_strdup_printf(NULL, "Lua: on packet %i Error during execution of Listener packet callback",lua_pinfo->num) : wmem_strdup_printf(NULL, "Lua: Error during execution of Listener packet callback") ; @@ -124,7 +125,7 @@ static tap_packet_status lua_tap_packet(void *tapdata, packet_info *pinfo, epan_ } static int tap_reset_cb_error_handler(lua_State* L) { - const gchar* error = lua_tostring(L,1); + const char* error = lua_tostring(L,1); report_failure("Lua: Error during execution of Listener reset callback:\n %s",error); return 0; } @@ -156,14 +157,14 @@ static void lua_tap_reset(void *tapdata) { } static int tap_draw_cb_error_handler(lua_State* L) { - const gchar* error = lua_tostring(L,1); + const char* error = lua_tostring(L,1); report_failure("Lua: Error during execution of Listener draw callback:\n %s",error); return 0; } static void lua_tap_draw(void *tapdata) { Listener tap = (Listener)tapdata; - const gchar* error; + const char* error; if (tap->draw_ref == LUA_NOREF) return; @@ -191,12 +192,12 @@ static void lua_tap_draw(void *tapdata) { } /* TODO: we should probably use a Lua table here */ -static GPtrArray *listeners = NULL; +static GPtrArray *listeners; static void deregister_Listener (lua_State* L _U_, Listener tap) { if (tap->all_fields) { - epan_set_always_visible(FALSE); - tap->all_fields = FALSE; + epan_set_always_visible(false); + tap->all_fields = false; } remove_tap_listener(tap); @@ -220,9 +221,9 @@ WSLUA_CONSTRUCTOR Listener_new(lua_State* L) { The default is `false`. Note: This impacts performance. */ - const gchar* tap_type = luaL_optstring(L,WSLUA_OPTARG_Listener_new_TAP,"frame"); - const gchar* filter = luaL_optstring(L,WSLUA_OPTARG_Listener_new_FILTER,NULL); - const gboolean all_fields = wslua_optbool(L, WSLUA_OPTARG_Listener_new_ALLFIELDS, FALSE); + const char* tap_type = luaL_optstring(L,WSLUA_OPTARG_Listener_new_TAP,"frame"); + const char* filter = luaL_optstring(L,WSLUA_OPTARG_Listener_new_FILTER,NULL); + const bool all_fields = wslua_optbool(L, WSLUA_OPTARG_Listener_new_ALLFIELDS, false); Listener tap; GString* error; @@ -257,7 +258,7 @@ WSLUA_CONSTRUCTOR Listener_new(lua_State* L) { } if (all_fields) { - epan_set_always_visible(TRUE); + epan_set_always_visible(true); } g_ptr_array_add(listeners, tap); @@ -267,8 +268,8 @@ WSLUA_CONSTRUCTOR Listener_new(lua_State* L) { } /* Allow dissector key names to be sorted alphabetically */ -static gint -compare_dissector_key_name(gconstpointer dissector_a, gconstpointer dissector_b) +static int +compare_dissector_key_name(const void *dissector_a, const void *dissector_b) { return strcmp((const char*)dissector_a, (const char*)dissector_b); } @@ -277,9 +278,6 @@ WSLUA_CONSTRUCTOR Listener_list (lua_State *L) { /* Gets a Lua array table of all registered `Listener` tap names. Note: This is an expensive operation, and should only be used for troubleshooting. - - @since 1.11.3 - ===== Example [source,lua] @@ -354,7 +352,7 @@ WSLUA_ATTRIBUTE_FUNC_SETTER(Listener,packet); /* WSLUA_ATTRIBUTE Listener_draw WO A function that will be called once every few seconds to redraw the GUI objects; - in TShark this funtion is called only at the very end of the capture file. + in TShark this function is called only at the very end of the capture file. When later called by Wireshark, the `draw` function will not be given any arguments. @@ -414,7 +412,7 @@ int Listener_register(lua_State* L) { return 0; } -static void deregister_tap_listener (gpointer data, gpointer userdata) { +static void deregister_tap_listener (void *data, void *userdata) { lua_State *L = (lua_State *) userdata; Listener tap = (Listener) data; deregister_Listener(L, tap); @@ -422,7 +420,7 @@ static void deregister_tap_listener (gpointer data, gpointer userdata) { int wslua_deregister_listeners(lua_State* L) { g_ptr_array_foreach(listeners, deregister_tap_listener, L); - g_ptr_array_free(listeners, TRUE); + g_ptr_array_free(listeners, true); listeners = NULL; return 0; diff --git a/epan/wslua/wslua_nstime.c b/epan/wslua/wslua_nstime.c index b3012e71..94db190a 100644 --- a/epan/wslua/wslua_nstime.c +++ b/epan/wslua/wslua_nstime.c @@ -54,9 +54,7 @@ WSLUA_METAMETHOD NSTime__call(lua_State* L) { /* Creates a NSTime object. */ } WSLUA_METHOD NSTime_tonumber(lua_State* L) { - /* Returns a Lua number of the `NSTime` representing seconds from epoch - @since 2.4.0 - */ + /* Returns a Lua number of the `NSTime` representing seconds from epoch. */ NSTime nstime = checkNSTime(L,1); lua_pushnumber(L, (lua_Number)nstime_to_sec(nstime)); WSLUA_RETURN(1); /* The Lua number. */ @@ -64,10 +62,10 @@ WSLUA_METHOD NSTime_tonumber(lua_State* L) { WSLUA_METAMETHOD NSTime__tostring(lua_State* L) { NSTime nstime = checkNSTime(L,1); - gchar *str; + char *str; long secs = (long)nstime->secs; - gint nsecs = nstime->nsecs; - gboolean negative_zero = FALSE; + int nsecs = nstime->nsecs; + bool negative_zero = false; /* Time is defined as sec + nsec/10^9, both parts can be negative. * Translate this into the more familiar sec.nsec notation instead. */ @@ -133,10 +131,10 @@ WSLUA_METAMETHOD NSTime__unm(lua_State* L) { /* Calculates the negative NSTime. WSLUA_METAMETHOD NSTime__eq(lua_State* L) { /* Compares two NSTimes. */ NSTime time1 = checkNSTime(L,1); NSTime time2 = checkNSTime(L,2); - gboolean result = FALSE; + bool result = false; if (nstime_cmp(time1, time2) == 0) - result = TRUE; + result = true; lua_pushboolean(L,result); @@ -146,10 +144,10 @@ WSLUA_METAMETHOD NSTime__eq(lua_State* L) { /* Compares two NSTimes. */ WSLUA_METAMETHOD NSTime__le(lua_State* L) { /* Compares two NSTimes. */ NSTime time1 = checkNSTime(L,1); NSTime time2 = checkNSTime(L,2); - gboolean result = FALSE; + bool result = false; if (nstime_cmp(time1, time2) <= 0) - result = TRUE; + result = true; lua_pushboolean(L,result); @@ -159,10 +157,10 @@ WSLUA_METAMETHOD NSTime__le(lua_State* L) { /* Compares two NSTimes. */ WSLUA_METAMETHOD NSTime__lt(lua_State* L) { /* Compares two NSTimes. */ NSTime time1 = checkNSTime(L,1); NSTime time2 = checkNSTime(L,2); - gboolean result = FALSE; + bool result = false; if (nstime_cmp(time1, time2) < 0) - result = TRUE; + result = true; lua_pushboolean(L,result); @@ -171,12 +169,12 @@ WSLUA_METAMETHOD NSTime__lt(lua_State* L) { /* Compares two NSTimes. */ /* WSLUA_ATTRIBUTE NSTime_secs RW The NSTime seconds. */ -WSLUA_ATTRIBUTE_NUMBER_GETTER(NSTime,secs); -WSLUA_ATTRIBUTE_NUMBER_SETTER(NSTime,secs,time_t); +WSLUA_ATTRIBUTE_INTEGER_GETTER(NSTime,secs); +WSLUA_ATTRIBUTE_INTEGER_SETTER(NSTime,secs,time_t); /* WSLUA_ATTRIBUTE NSTime_nsecs RW The NSTime nano seconds. */ -WSLUA_ATTRIBUTE_NUMBER_GETTER(NSTime,nsecs); -WSLUA_ATTRIBUTE_NUMBER_SETTER(NSTime,nsecs,int); +WSLUA_ATTRIBUTE_INTEGER_GETTER(NSTime,nsecs); +WSLUA_ATTRIBUTE_INTEGER_SETTER(NSTime,nsecs,int); /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */ static int NSTime__gc(lua_State* L) { diff --git a/epan/wslua/wslua_pinfo.c b/epan/wslua/wslua_pinfo.c index a735d601..1b0bb621 100644 --- a/epan/wslua/wslua_pinfo.c +++ b/epan/wslua/wslua_pinfo.c @@ -30,18 +30,18 @@ * see comment on wslua_tvb.c */ -static GPtrArray* outstanding_Pinfo = NULL; -static GPtrArray* outstanding_PrivateTable = NULL; +static GPtrArray* outstanding_Pinfo; +static GPtrArray* outstanding_PrivateTable; -CLEAR_OUTSTANDING(Pinfo,expired, TRUE) -CLEAR_OUTSTANDING(PrivateTable,expired, TRUE) +CLEAR_OUTSTANDING(Pinfo,expired, true) +CLEAR_OUTSTANDING(PrivateTable,expired, true) Pinfo* push_Pinfo(lua_State* L, packet_info* ws_pinfo) { Pinfo pinfo = NULL; if (ws_pinfo) { pinfo = (Pinfo)g_malloc(sizeof(struct _wslua_pinfo)); pinfo->ws_pinfo = ws_pinfo; - pinfo->expired = FALSE; + pinfo->expired = false; g_ptr_array_add(outstanding_Pinfo,pinfo); } return pushPinfo(L,pinfo); @@ -65,7 +65,7 @@ WSLUA_METAMETHOD PrivateTable__tostring(lua_State* L) { keys = g_hash_table_get_keys (priv->table); key = g_list_first (keys); while (key) { - key_string = g_string_append (key_string, (const gchar *)key->data); + key_string = g_string_append (key_string, (const char *)key->data); key = g_list_next (key); if (key) { key_string = g_string_append_c (key_string, ','); @@ -83,10 +83,10 @@ WSLUA_METAMETHOD PrivateTable__tostring(lua_State* L) { static int PrivateTable__index(lua_State* L) { /* Gets the text of a specific entry. */ PrivateTable priv = checkPrivateTable(L,1); - const gchar* name = luaL_checkstring(L,2); - const gchar* string; + const char* name = luaL_checkstring(L,2); + const char* string; - string = (const gchar *)(g_hash_table_lookup (priv->table, name)); + string = (const char *)(g_hash_table_lookup (priv->table, name)); if (string) { lua_pushstring(L, string); @@ -100,8 +100,8 @@ static int PrivateTable__index(lua_State* L) { static int PrivateTable__newindex(lua_State* L) { /* Sets the text of a specific entry. */ PrivateTable priv = checkPrivateTable(L,1); - const gchar* name = luaL_checkstring(L,2); - const gchar* string = NULL; + const char* name = luaL_checkstring(L,2); + const char* string = NULL; if (lua_isstring(L,3)) { /* This also catches numbers, which is converted to string */ @@ -115,9 +115,9 @@ static int PrivateTable__newindex(lua_State* L) { } if (string) { - g_hash_table_replace (priv->table, (gpointer) g_strdup(name), (gpointer) g_strdup(string)); + g_hash_table_replace (priv->table, (void *) g_strdup(name), (void *) g_strdup(string)); } else { - g_hash_table_remove (priv->table, (gconstpointer) name); + g_hash_table_remove (priv->table, (const void *) name); } return 1; @@ -130,7 +130,7 @@ static int PrivateTable__gc(lua_State* L) { if (!priv) return 0; if (!priv->expired) { - priv->expired = TRUE; + priv->expired = true; } else { if (priv->is_allocated) { g_hash_table_destroy (priv->table); @@ -182,17 +182,17 @@ static int Pinfo__tostring(lua_State *L) { lua_pushstring(L,"a Pinfo"); return 1 #define PINFO_NAMED_BOOLEAN_SETTER(name,member) \ WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER(Pinfo,name,ws_pinfo->member) -#define PINFO_NUMBER_GETTER(name) \ - WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(Pinfo,name,ws_pinfo->name) +#define PINFO_INTEGER_GETTER(name) \ + WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(Pinfo,name,ws_pinfo->name) -#define PINFO_NAMED_NUMBER_GETTER(name,member) \ - WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(Pinfo,name,ws_pinfo->member) +#define PINFO_NAMED_INTEGER_GETTER(name,member) \ + WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(Pinfo,name,ws_pinfo->member) #define PINFO_NUMBER_SETTER(name,cast) \ - WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(Pinfo,name,ws_pinfo->name,cast) + WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(Pinfo,name,ws_pinfo->name,cast) -#define PINFO_NAMED_NUMBER_SETTER(name,member,cast) \ - WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(Pinfo,name,ws_pinfo->member,cast) +#define PINFO_NAMED_INTEGER_SETTER(name,member,cast) \ + WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(Pinfo,name,ws_pinfo->member,cast) static double lua_nstime_to_sec(const nstime_t *nstime) @@ -201,7 +201,7 @@ lua_nstime_to_sec(const nstime_t *nstime) } static double -lua_delta_nstime_to_sec(const Pinfo pinfo, const frame_data *fd, guint32 prev_num) +lua_delta_nstime_to_sec(const Pinfo pinfo, const frame_data *fd, uint32_t prev_num) { nstime_t del; @@ -214,13 +214,13 @@ lua_delta_nstime_to_sec(const Pinfo pinfo, const frame_data *fd, guint32 prev_nu PINFO_NAMED_BOOLEAN_GETTER(visited,fd->visited); /* WSLUA_ATTRIBUTE Pinfo_number RO The number of this packet in the current file. */ -PINFO_NAMED_NUMBER_GETTER(number,num); +PINFO_NAMED_INTEGER_GETTER(number,num); /* WSLUA_ATTRIBUTE Pinfo_len RO The length of the frame. */ -PINFO_NAMED_NUMBER_GETTER(len,fd->pkt_len); +PINFO_NAMED_INTEGER_GETTER(len,fd->pkt_len); /* WSLUA_ATTRIBUTE Pinfo_caplen RO The captured length of the frame. */ -PINFO_NAMED_NUMBER_GETTER(caplen,fd->cap_len); +PINFO_NAMED_INTEGER_GETTER(caplen,fd->cap_len); /* WSLUA_ATTRIBUTE Pinfo_abs_ts RO When the packet was captured. */ WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(Pinfo,abs_ts,lua_nstime_to_sec(&obj->ws_pinfo->abs_ts)); @@ -238,15 +238,21 @@ WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(Pinfo,delta_dis_ts,lua_delta_nstime_to_sec(o WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(Pinfo,curr_proto,ws_pinfo->current_proto); /* WSLUA_ATTRIBUTE Pinfo_can_desegment RW Set if this segment could be desegmented. */ -PINFO_NUMBER_GETTER(can_desegment); -PINFO_NUMBER_SETTER(can_desegment,guint16); +PINFO_INTEGER_GETTER(can_desegment); +PINFO_NUMBER_SETTER(can_desegment,uint16_t); + +/* WSLUA_ATTRIBUTE Pinfo_saved_can_desegment RO Value of can_desegment before the current dissector was called. + Supplied so that proxy protocols like SOCKS can restore it to whatever the previous dissector (e.g. TCP) set it, + so that the dissectors they call are desegmented via the previous dissector. + @since 4.3.1 */ +PINFO_INTEGER_GETTER(saved_can_desegment); /* WSLUA_ATTRIBUTE Pinfo_desegment_len RW Estimated number of additional bytes required for completing the PDU. */ -PINFO_NUMBER_GETTER(desegment_len); -PINFO_NUMBER_SETTER(desegment_len,guint32); +PINFO_INTEGER_GETTER(desegment_len); +PINFO_NUMBER_SETTER(desegment_len,uint32_t); /* WSLUA_ATTRIBUTE Pinfo_desegment_offset RW Offset in the tvbuff at which the dissector will continue processing when next called. */ -PINFO_NUMBER_GETTER(desegment_offset); +PINFO_INTEGER_GETTER(desegment_offset); PINFO_NUMBER_SETTER(desegment_offset,int); /* WSLUA_ATTRIBUTE Pinfo_fragmented RO If the protocol is only a fragment. */ @@ -257,21 +263,22 @@ PINFO_NAMED_BOOLEAN_GETTER(in_error_pkt,flags.in_error_pkt); PINFO_NAMED_BOOLEAN_SETTER(in_error_pkt,flags.in_error_pkt); /* WSLUA_ATTRIBUTE Pinfo_match_uint RO Matched uint for calling subdissector from table. */ -PINFO_NUMBER_GETTER(match_uint); +PINFO_INTEGER_GETTER(match_uint); /* WSLUA_ATTRIBUTE Pinfo_match_string RO Matched string for calling subdissector from table. */ WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(Pinfo,match_string,ws_pinfo->match_string); /* WSLUA_ATTRIBUTE Pinfo_port_type RW Type of Port of .src_port and .dst_port. */ -PINFO_NAMED_NUMBER_GETTER(port_type,ptype); +PINFO_NAMED_INTEGER_GETTER(port_type,ptype); +PINFO_NAMED_INTEGER_SETTER(port_type,ptype,uint8_t); /* WSLUA_ATTRIBUTE Pinfo_src_port RW Source Port of this Packet. */ -PINFO_NAMED_NUMBER_GETTER(src_port,srcport); -PINFO_NAMED_NUMBER_SETTER(src_port,srcport,guint32); +PINFO_NAMED_INTEGER_GETTER(src_port,srcport); +PINFO_NAMED_INTEGER_SETTER(src_port,srcport,uint32_t); /* WSLUA_ATTRIBUTE Pinfo_dst_port RW Destination Port of this Packet. */ -PINFO_NAMED_NUMBER_GETTER(dst_port,destport); -PINFO_NAMED_NUMBER_SETTER(dst_port,destport,guint32); +PINFO_NAMED_INTEGER_GETTER(dst_port,destport); +PINFO_NAMED_INTEGER_SETTER(dst_port,destport,uint32_t); /* WSLUA_ATTRIBUTE Pinfo_dl_src RW Data Link Source Address of this Packet. */ PINFO_ADDRESS_GETTER(dl_src); @@ -298,7 +305,7 @@ PINFO_ADDRESS_GETTER(dst); PINFO_ADDRESS_SETTER(dst); /* WSLUA_ATTRIBUTE Pinfo_p2p_dir RW Direction of this Packet. (incoming / outgoing) */ -PINFO_NUMBER_GETTER(p2p_dir); +PINFO_INTEGER_GETTER(p2p_dir); PINFO_NUMBER_SETTER(p2p_dir,int); /* WSLUA_ATTRIBUTE Pinfo_match RO Port/Data we are matching. */ @@ -308,7 +315,7 @@ static int Pinfo_get_match(lua_State *L) { if (pinfo->ws_pinfo->match_string) { lua_pushstring(L,pinfo->ws_pinfo->match_string); } else { - lua_pushnumber(L,(lua_Number)(pinfo->ws_pinfo->match_uint)); + lua_pushinteger(L,(lua_Integer)(pinfo->ws_pinfo->match_uint)); } return 1; @@ -319,11 +326,11 @@ static int Pinfo_get_match(lua_State *L) { static int Pinfo_get_columns(lua_State *L) { Columns cols = NULL; Pinfo pinfo = checkPinfo(L,1); - const gchar* colname = luaL_optstring(L,2,NULL); + const char* colname = luaL_optstring(L,2,NULL); cols = (Columns)g_malloc(sizeof(struct _wslua_cols)); cols->cinfo = pinfo->ws_pinfo->cinfo; - cols->expired = FALSE; + cols->expired = false; if (!colname) { Push_Columns(L,cols); @@ -340,18 +347,18 @@ static int Pinfo_get_columns(lua_State *L) { static int Pinfo_get_private(lua_State *L) { PrivateTable priv = NULL; Pinfo pinfo = checkPinfo(L,1); - const gchar* privname = luaL_optstring(L,2,NULL); - gboolean is_allocated = FALSE; + const char* privname = luaL_optstring(L,2,NULL); + bool is_allocated = false; if (!pinfo->ws_pinfo->private_table) { pinfo->ws_pinfo->private_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - is_allocated = TRUE; + is_allocated = true; } priv = (PrivateTable)g_malloc(sizeof(struct _wslua_private_table)); priv->table = pinfo->ws_pinfo->private_table; priv->is_allocated = is_allocated; - priv->expired = FALSE; + priv->expired = false; if (!privname) { PUSH_PRIVATE_TABLE(L,priv); @@ -420,7 +427,7 @@ static int Pinfo__gc(lua_State* L) { if (!pinfo) return 0; if (!pinfo->expired) - pinfo->expired = TRUE; + pinfo->expired = true; else g_free(pinfo); @@ -449,7 +456,7 @@ WSLUA_ATTRIBUTES Pinfo_attributes[] = { WSLUA_ATTRIBUTE_RWREG(Pinfo,dl_dst), WSLUA_ATTRIBUTE_RWREG(Pinfo,net_src), WSLUA_ATTRIBUTE_RWREG(Pinfo,net_dst), - WSLUA_ATTRIBUTE_ROREG(Pinfo,port_type), + WSLUA_ATTRIBUTE_RWREG(Pinfo,port_type), WSLUA_ATTRIBUTE_RWREG(Pinfo,src_port), WSLUA_ATTRIBUTE_RWREG(Pinfo,dst_port), WSLUA_ATTRIBUTE_ROREG(Pinfo,match), @@ -457,6 +464,7 @@ WSLUA_ATTRIBUTES Pinfo_attributes[] = { WSLUA_ATTRIBUTE_ROREG(Pinfo,columns), { "cols", Pinfo_get_columns, NULL }, WSLUA_ATTRIBUTE_RWREG(Pinfo,can_desegment), + WSLUA_ATTRIBUTE_ROREG(Pinfo,saved_can_desegment), WSLUA_ATTRIBUTE_RWREG(Pinfo,desegment_len), WSLUA_ATTRIBUTE_RWREG(Pinfo,desegment_offset), WSLUA_ATTRIBUTE_ROREG(Pinfo,private), @@ -476,7 +484,13 @@ WSLUA_META Pinfo_meta[] = { int Pinfo_register(lua_State* L) { WSLUA_REGISTER_META_WITH_ATTRS(Pinfo); + if (outstanding_Pinfo != NULL) { + g_ptr_array_unref(outstanding_Pinfo); + } outstanding_Pinfo = g_ptr_array_new(); + if (outstanding_PrivateTable != NULL) { + g_ptr_array_unref(outstanding_PrivateTable); + } outstanding_PrivateTable = g_ptr_array_new(); return 0; } diff --git a/epan/wslua/wslua_pref.c b/epan/wslua/wslua_pref.c index 234170d3..52b3706a 100644 --- a/epan/wslua/wslua_pref.c +++ b/epan/wslua/wslua_pref.c @@ -29,9 +29,9 @@ static range_t* get_range(lua_State *L, int idx_r, int idx_m); static enum_val_t* get_enum(lua_State *L, int idx) { double seq; - const gchar *str1, *str2; + const char *str1, *str2; enum_val_t *ret, last = {NULL, NULL, -1}; - GArray* es = g_array_new(TRUE,TRUE,sizeof(enum_val_t)); + GArray* es = g_array_new(true,true,sizeof(enum_val_t)); luaL_checktype(L, idx, LUA_TTABLE); lua_pushnil(L); /* first key */ @@ -44,7 +44,7 @@ static enum_val_t* get_enum(lua_State *L, int idx) lua_next(L, -2); if (! lua_isstring(L,-1)) { luaL_argerror(L,idx,"First value of an enum table must be string"); - g_array_free(es,TRUE); + g_array_free(es,true); return NULL; } str1 = lua_tostring(L, -1); @@ -53,7 +53,7 @@ static enum_val_t* get_enum(lua_State *L, int idx) lua_next(L, -2); if (! lua_isstring(L,-1)) { luaL_argerror(L,idx,"Second value of an enum table must be string"); - g_array_free(es,TRUE); + g_array_free(es,true); return NULL; } str2 = lua_tostring(L, -1); @@ -62,14 +62,14 @@ static enum_val_t* get_enum(lua_State *L, int idx) lua_next(L, -2); if (! lua_isnumber(L,-1)) { luaL_argerror(L,idx,"Third value of an enum table must be an integer"); - g_array_free(es,TRUE); + g_array_free(es,true); return NULL; } seq = lua_tonumber(L, -1); e.name = g_strdup(str1); e.description = g_strdup(str2); - e.value = (guint32)seq; + e.value = (uint32_t)seq; g_array_append_val(es,e); @@ -78,14 +78,14 @@ static enum_val_t* get_enum(lua_State *L, int idx) g_array_append_val(es,last); - ret = (enum_val_t*)(void*)g_array_free(es, FALSE); + ret = (enum_val_t*)(void*)g_array_free(es, false); return ret; } static int new_pref(lua_State* L, pref_type_t type) { - const gchar* label = luaL_optstring(L,1,NULL); - const gchar* descr = luaL_optstring(L,3,""); + const char* label = luaL_optstring(L,1,NULL); + const char* descr = luaL_optstring(L,3,""); Pref pref = g_new0(wslua_pref_t, 1); pref->label = g_strdup(label); @@ -95,17 +95,17 @@ static int new_pref(lua_State* L, pref_type_t type) { switch(type) { case PREF_BOOL: { - gboolean def = wslua_toboolean(L,2); + bool def = wslua_toboolean(L,2); pref->value.b = def; break; } case PREF_UINT: { - guint32 def = wslua_optgint32(L,2,0); + uint32_t def = wslua_optint32(L,2,0); pref->value.u = def; break; } case PREF_STRING: { - gchar* def = g_strdup(luaL_optstring(L,2,"")); + char* def = g_strdup(luaL_optstring(L,2,"")); /* * prefs_register_string_preference() assumes that the * variable for the preference points to a static @@ -132,9 +132,9 @@ static int new_pref(lua_State* L, pref_type_t type) { break; } case PREF_ENUM: { - guint32 def = wslua_optgint32(L,2,0); + uint32_t def = wslua_optint32(L,2,0); enum_val_t *enum_val = get_enum(L,4); - gboolean radio = wslua_toboolean(L,5); + bool radio = wslua_toboolean(L,5); pref->value.e = def; pref->info.enum_info.enumvals = enum_val; pref->info.enum_info.radio_buttons = radio; @@ -142,7 +142,7 @@ static int new_pref(lua_State* L, pref_type_t type) { } case PREF_RANGE: { range_t *range = get_range(L,2,4); - guint32 max = wslua_optgint32(L,4,0); + uint32_t max = wslua_optint32(L,4,0); pref->value.r = range; pref->info.max_value = max; break; @@ -177,7 +177,7 @@ WSLUA_CONSTRUCTOR Pref_bool(lua_State* L) { #define WSLUA_ARG_Pref_bool_LABEL 1 /* The Label (text in the right side of the preference input) for this preference. */ #define WSLUA_ARG_Pref_bool_DEFAULT 2 /* The default value for this preference. */ -#define WSLUA_ARG_Pref_bool_DESCR 3 /* A description of this preference. */ +#define WSLUA_ARG_Pref_bool_DESCRIPTION 3 /* A description of this preference. */ return new_pref(L,PREF_BOOL); } @@ -186,7 +186,7 @@ WSLUA_CONSTRUCTOR Pref_uint(lua_State* L) { #define WSLUA_ARG_Pref_uint_LABEL 1 /* The Label (text in the right side of the preference input) for this preference. */ #define WSLUA_ARG_Pref_uint_DEFAULT 2 /* The default value for this preference. */ -#define WSLUA_ARG_Pref_uint_DESCR 3 /* A description of what this preference is. */ +#define WSLUA_ARG_Pref_uint_DESCRIPTION 3 /* A description of what this preference is. */ return new_pref(L,PREF_UINT); } @@ -195,7 +195,7 @@ WSLUA_CONSTRUCTOR Pref_string(lua_State* L) { #define WSLUA_ARG_Pref_string_LABEL 1 /* The Label (text in the right side of the preference input) for this preference. */ #define WSLUA_ARG_Pref_string_DEFAULT 2 /* The default value for this preference. */ -#define WSLUA_ARG_Pref_string_DESCR 3 /* A description of what this preference is. */ +#define WSLUA_ARG_Pref_string_DESCRIPTION 3 /* A description of what this preference is. */ return new_pref(L,PREF_STRING); } @@ -240,7 +240,7 @@ WSLUA_CONSTRUCTOR Pref_enum(lua_State* L) { #define WSLUA_ARG_Pref_enum_LABEL 1 /* The Label (text in the right side of the preference input) for this preference. */ #define WSLUA_ARG_Pref_enum_DEFAULT 2 /* The default value for this preference. */ -#define WSLUA_ARG_Pref_enum_DESCR 3 /* A description of what this preference is. */ +#define WSLUA_ARG_Pref_enum_DESCRIPTION 3 /* A description of what this preference is. */ #define WSLUA_ARG_Pref_enum_ENUM 4 /* An enum Lua table. */ #define WSLUA_ARG_Pref_enum_RADIO 5 /* Radio button (true) or Combobox (false). */ return new_pref(L,PREF_ENUM); @@ -252,7 +252,7 @@ WSLUA_CONSTRUCTOR Pref_range(lua_State* L) { input) for this preference. */ #define WSLUA_ARG_Pref_range_DEFAULT 2 /* The default value for this preference, e.g., "53", "10-30", or "10-30,53,55,100-120". */ -#define WSLUA_ARG_Pref_range_DESCR 3 /* A description of what this preference is. */ +#define WSLUA_ARG_Pref_range_DESCRIPTION 3 /* A description of what this preference is. */ #define WSLUA_ARG_Pref_range_MAX 4 /* The maximum value. */ return new_pref(L,PREF_RANGE); } @@ -260,16 +260,16 @@ WSLUA_CONSTRUCTOR Pref_range(lua_State* L) { WSLUA_CONSTRUCTOR Pref_statictext(lua_State* L) { /* Creates a static text string to be added to a <<lua_class_attrib_proto_prefs,`Proto.prefs`>> Lua table. */ #define WSLUA_ARG_Pref_statictext_LABEL 1 /* The static text. */ -#define WSLUA_ARG_Pref_statictext_DESCR 2 /* The static text description. */ +#define WSLUA_ARG_Pref_statictext_DESCRIPTION 2 /* The static text description. */ return new_pref(L,PREF_STATIC_TEXT); } static range_t* get_range(lua_State *L, int idx_r, int idx_m) { static range_t *ret = NULL; - const gchar *pattern = luaL_checkstring(L, idx_r); + const char *pattern = luaL_checkstring(L, idx_r); - switch (range_convert_str(wmem_epan_scope(), &ret, pattern, wslua_togint32(L, idx_m))) { + switch (range_convert_str(wmem_epan_scope(), &ret, pattern, wslua_toint32(L, idx_m))) { case CVT_NO_ERROR: break; case CVT_SYNTAX_ERROR: @@ -358,10 +358,10 @@ WSLUA_METAMETHOD Prefs__newindex(lua_State* L) { #define WSLUA_ARG_Prefs__newindex_PREF 3 /* A valid but still unassigned Pref object. */ Pref prefs_p = checkPrefs(L,1); - const gchar* name = luaL_checkstring(L,WSLUA_ARG_Prefs__newindex_NAME); + const char* name = luaL_checkstring(L,WSLUA_ARG_Prefs__newindex_NAME); Pref pref = checkPref(L,WSLUA_ARG_Prefs__newindex_PREF); Pref p; - const gchar *c; + const char *c; if (! prefs_p ) return 0; @@ -500,7 +500,7 @@ WSLUA_METAMETHOD Prefs__index(lua_State* L) { #define WSLUA_ARG_Prefs__index_NAME 2 /* The abbreviation of this preference. */ Pref prefs_p = checkPrefs(L,1); - const gchar* name = luaL_checkstring(L,WSLUA_ARG_Prefs__index_NAME); + const char* name = luaL_checkstring(L,WSLUA_ARG_Prefs__index_NAME); if (! prefs_p ) return 0; @@ -515,9 +515,9 @@ WSLUA_METAMETHOD Prefs__index(lua_State* L) { if ( g_str_equal(prefs_p->name,name) ) { switch (prefs_p->type) { case PREF_BOOL: lua_pushboolean(L, prefs_p->value.b); break; - case PREF_UINT: lua_pushnumber(L,(lua_Number)prefs_p->value.u); break; + case PREF_UINT: lua_pushinteger(L,(lua_Integer)prefs_p->value.u); break; case PREF_STRING: lua_pushstring(L,prefs_p->value.s); break; - case PREF_ENUM: lua_pushnumber(L,(lua_Number)prefs_p->value.e); break; + case PREF_ENUM: lua_pushinteger(L,(lua_Integer)prefs_p->value.e); break; case PREF_RANGE: { char *push_str = range_convert_range(NULL, prefs_p->value.r); diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index b7f170d7..6b91e1ca 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -40,7 +40,7 @@ typedef struct _func_saver { int dissect_ref; } func_saver_t; -static GPtrArray* outstanding_FuncSavers = NULL; +static GPtrArray* outstanding_FuncSavers; void clear_outstanding_FuncSavers(void) { while (outstanding_FuncSavers->len) { @@ -70,11 +70,11 @@ static int protocols_table_ref = LUA_NOREF; WSLUA_CONSTRUCTOR Proto_new(lua_State* L) { /* Creates a new <<lua_class_Proto,`Proto`>> object. */ #define WSLUA_ARG_Proto_new_NAME 1 /* The name of the protocol. */ -#define WSLUA_ARG_Proto_new_DESC 2 /* A Long Text description of the protocol (usually lowercase). */ - const gchar* name = luaL_checkstring(L,WSLUA_ARG_Proto_new_NAME); - const gchar* desc = luaL_checkstring(L,WSLUA_ARG_Proto_new_DESC); +#define WSLUA_ARG_Proto_new_DESCRIPTION 2 /* A Long Text description of the protocol (usually lowercase). */ + const char* name = luaL_checkstring(L,WSLUA_ARG_Proto_new_NAME); + const char* desc = luaL_checkstring(L,WSLUA_ARG_Proto_new_DESCRIPTION); Proto proto; - gchar *loname, *hiname; + char *loname, *hiname; /* TODO: should really make a common function for all of wslua that does checkstring and non-empty at same time */ if (!name[0]) { @@ -83,12 +83,12 @@ WSLUA_CONSTRUCTOR Proto_new(lua_State* L) { /* Creates a new <<lua_class_Proto,` } if (!desc[0]) { - WSLUA_ARG_ERROR(Proto_new,DESC,"must not be an empty string"); + WSLUA_ARG_ERROR(Proto_new,DESCRIPTION,"must not be an empty string"); return 0; } if (proto_name_already_registered(desc)) { - WSLUA_ARG_ERROR(Proto_new,DESC,"there cannot be two protocols with the same description"); + WSLUA_ARG_ERROR(Proto_new,DESCRIPTION,"there cannot be two protocols with the same description"); return 0; } @@ -116,8 +116,8 @@ WSLUA_CONSTRUCTOR Proto_new(lua_State* L) { /* Creates a new <<lua_class_Proto,` proto->desc = g_strdup(desc); proto->hfid = proto_register_protocol(proto->desc,hiname,loname); proto->ett = -1; - proto->is_postdissector = FALSE; - proto->expired = FALSE; + proto->is_postdissector = false; + proto->expired = false; lua_newtable (L); proto->fields = luaL_ref(L, LUA_REGISTRYINDEX); @@ -150,7 +150,7 @@ WSLUA_CONSTRUCTOR Proto_new(lua_State* L) { /* Creates a new <<lua_class_Proto,` WSLUA_METAMETHOD Proto__call(lua_State* L) { /* Creates a <<lua_class_Proto,`Proto`>> object. */ #define WSLUA_ARG_Proto__call_NAME 1 /* The name of the protocol. */ -#define WSLUA_ARG_Proto__call_DESC 2 /* A Long Text description of the protocol (usually lowercase). */ +#define WSLUA_ARG_Proto__call_DESCRIPTION 2 /* A Long Text description of the protocol (usually lowercase). */ lua_remove(L,1); /* remove the table */ WSLUA_RETURN(Proto_new(L)); /* The new <<lua_class_Proto,`Proto`>> object. */ } @@ -171,7 +171,7 @@ WSLUA_FUNCTION wslua_register_postdissector(lua_State* L) { Note: This impacts performance (default=false). */ Proto proto = checkProto(L,WSLUA_ARG_register_postdissector_PROTO); - const gboolean all_fields = wslua_optbool(L, WSLUA_OPTARG_register_postdissector_ALLFIELDS, FALSE); + const bool all_fields = wslua_optbool(L, WSLUA_OPTARG_register_postdissector_ALLFIELDS, false); if(!proto->is_postdissector) { if (! proto->handle) { @@ -179,7 +179,7 @@ WSLUA_FUNCTION wslua_register_postdissector(lua_State* L) { } register_postdissector(proto->handle); - proto->is_postdissector = TRUE; + proto->is_postdissector = true; } else { luaL_argerror(L,1,"this protocol is already registered as postdissector"); } @@ -195,7 +195,7 @@ WSLUA_FUNCTION wslua_register_postdissector(lua_State* L) { * * If not, this is overkill. */ - epan_set_always_visible(TRUE); + epan_set_always_visible(true); } return 0; @@ -222,8 +222,6 @@ WSLUA_METHOD Proto_register_heuristic(lua_State* L) { it will be treated the same as a `false` return for the heuristic; if a positive or negative number is returned, then the it will be treated the same as a `true` return for the heuristic, meaning the packet is for this protocol and no other heuristic will be tried. - - @since 1.11.3 */ #define WSLUA_ARG_Proto_register_heuristic_LISTNAME 2 /* The heuristic list name this function is a heuristic for (e.g., "udp" or @@ -231,11 +229,11 @@ WSLUA_METHOD Proto_register_heuristic(lua_State* L) { #define WSLUA_ARG_Proto_register_heuristic_FUNC 3 /* A Lua function that will be invoked for heuristic dissection. */ Proto proto = checkProto(L,1); - const gchar *listname = luaL_checkstring(L, WSLUA_ARG_Proto_register_heuristic_LISTNAME); - const gchar *proto_name = proto->name; + const char *listname = luaL_checkstring(L, WSLUA_ARG_Proto_register_heuristic_LISTNAME); + const char *proto_name = proto->name; const int top _U_ = lua_gettop(L); - gchar *short_name; + char *short_name; if (!proto_name || proto->hfid == -1) { /* this shouldn't happen - internal bug if it does */ @@ -432,18 +430,78 @@ static int Proto_get_fields(lua_State* L) { return 1; } +static bool Proto_append_ProtoField(Proto proto, ProtoField f) { + + if (f->hfid != -2) { + // Already registered + return false; + } + hf_register_info hfri = { NULL, { NULL, NULL, FT_NONE, 0, NULL, 0, NULL, HFILL } }; + int* ettp = NULL; + ettp = &(f->ett); + + hfri.p_id = &(f->hfid); + hfri.hfinfo.name = f->name; + hfri.hfinfo.abbrev = f->abbrev; + hfri.hfinfo.type = f->type; + hfri.hfinfo.display = f->base; + hfri.hfinfo.strings = VALS(f->vs); + hfri.hfinfo.bitmask = f->mask; + hfri.hfinfo.blurb = f->blob; + + f->hfid = -1; + g_array_append_val(proto->hfa,hfri); + g_array_append_val(proto->etta,ettp); + + return true; +} + static int Proto_set_fields(lua_State* L) { Proto proto = checkProto(L,1); #define FIELDS_TABLE 2 #define NEW_TABLE 3 #define NEW_FIELD 3 + /* + * XXX - This is a "setter", but it really appends any ProtoFields to + * the Lua Table without removing any existing ones. + */ + + if (proto->hfa) { + /* This Proto's ProtoFields were already registered in Proto_commit. + * Deregister the existing array with epan so we can add new ones. + * (Appending to the GArray and registering only the new ones would + * have a use-after-free, for reasons mentioned in proto.c ) + * XXX - What is the reason for waiting and registering all + * at once in Proto_commit instead of doing it here every time? + */ + if (proto->hfa->len) { + proto_add_deregistered_data(g_array_free(proto->hfa,false)); + } else { + g_array_free(proto->hfa,true); + } + /* No need for deferred deletion of subtree indexes */ + g_array_free(proto->etta,true); + proto->hfa = g_array_new(true,true,sizeof(hf_register_info)); + proto->etta = g_array_new(true,true,sizeof(int*)); + } + lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields); lua_insert(L,FIELDS_TABLE); if( lua_istable(L,NEW_TABLE)) { for (lua_pushnil(L); lua_next(L, NEW_TABLE); ) { if (isProtoField(L,5)) { + if (proto->hfa) { + ProtoField f = toProtoField(L,5); + // XXX this will leak resources on error + // If this continued and registered the field array, it + // wouldn't leak. We could perhaps print a warning or even + // err after registration. + if (!Proto_append_ProtoField(proto, f)) { + return luaL_error(L,"%s is already registered; fields can be registered only once", f->abbrev); + } + } /* luaL_ref returns a reference. lua_next will return not * just occupied entries in the table, but also references * used to store unused/deleted entries in the hash table @@ -476,6 +534,16 @@ static int Proto_set_fields(lua_State* L) { } } } else if (isProtoField(L,NEW_FIELD)){ + if (proto->hfa) { + ProtoField f = toProtoField(L,NEW_FIELD); + // XXX this will leak resources on error + // If this continued and registered the field array, it wouldn't + // leak. We could perhaps print a warning or even err after + // registration. + if (!Proto_append_ProtoField(proto, f)) { + return luaL_error(L,"%s is already registered; fields can be registered only once", f->abbrev); + } + } lua_pushvalue(L, NEW_FIELD); luaL_ref(L,FIELDS_TABLE); @@ -483,40 +551,94 @@ static int Proto_set_fields(lua_State* L) { return luaL_error(L,"either a ProtoField or an array of protofields"); } - /* XXX - I don't think this is necessary. */ + if (proto->hfa && proto->hfa->len) { + /* register the proto fields */ + proto_register_field_array(proto->hfid,&g_array_index(proto->hfa, hf_register_info, 0),proto->hfa->len); + proto_register_subtree_array(&g_array_index(proto->etta, int*, 0),proto->etta->len); + } + lua_pushvalue(L, 3); return 1; } -/* WSLUA_ATTRIBUTE Proto_experts RW The expert info Lua table of this `Proto`. - - @since 1.11.3 - */ +/* WSLUA_ATTRIBUTE Proto_experts RW The expert info Lua table of this `Proto`. */ static int Proto_get_experts(lua_State* L) { Proto proto = checkProto(L,1); lua_rawgeti(L, LUA_REGISTRYINDEX, proto->expert_info_table_ref); return 1; } +static bool Proto_append_ProtoExpert(Proto proto, ProtoExpert e) { + + if (e->ids.ei != EI_INIT_EI || e->ids.hf != -2) { + return false; + } + ei_register_info eiri = { NULL, { NULL, 0, 0, NULL, EXPFILL } }; + + eiri.ids = &(e->ids); + eiri.eiinfo.name = e->abbrev; + eiri.eiinfo.group = e->group; + eiri.eiinfo.severity = e->severity; + eiri.eiinfo.summary = e->text; + + e->ids.hf = -1; + g_array_append_val(proto->eia,eiri); + + return true; +} + static int Proto_set_experts(lua_State* L) { Proto proto = checkProto(L,1); #define EI_TABLE 2 #define NEW_TABLE 3 #define NEW_FIELD 3 + /* + * XXX - This is a "setter", but it really appends any ProtoExperts to + * the Lua Table without removing any existing ones. + */ + + if (proto->eia) { + /* This Proto's ProtoExperts were already registered in Proto_commit. + * Deregister the existing array with epan so we can add new ones. + * XXX - What is the reason for waiting and registering all at + * at once in Proto_commit instead of doing it here every time? + */ + if (proto->eia && proto->eia->len) { + proto_add_deregistered_data(g_array_free(proto->eia,false)); + } else { + g_array_free(proto->eia,true); + } + proto->eia = g_array_new(true,true,sizeof(ei_register_info)); + } + lua_rawgeti(L, LUA_REGISTRYINDEX, proto->expert_info_table_ref); lua_insert(L,EI_TABLE); if( lua_istable(L,NEW_TABLE)) { for (lua_pushnil(L); lua_next(L, NEW_TABLE); ) { if (isProtoExpert(L,5)) { + if (proto->eia) { + ProtoExpert e = toProtoExpert(L, NEW_FIELD); + + if (!Proto_append_ProtoExpert(proto, e)) { + return luaL_error(L,"%s is already registered; expert fields can be registered only once", e->abbrev); + } + } luaL_ref(L,EI_TABLE); } else if (! lua_isnil(L,5) ) { return luaL_error(L,"only ProtoExperts should be in the table"); } } } else if (isProtoExpert(L,NEW_FIELD)){ + if (proto->eia) { + ProtoExpert e = toProtoExpert(L, NEW_FIELD); + + if (!Proto_append_ProtoExpert(proto, e)) { + return luaL_error(L,"%s is already registered; expert fields can be registered only once", e->abbrev); + } + } lua_pushvalue(L, NEW_FIELD); luaL_ref(L,EI_TABLE); @@ -537,7 +659,7 @@ static int Proto__gc(lua_State* L) { Proto proto = toProto(L,1); if (!proto->expired) { - proto->expired = TRUE; + proto->expired = true; } else if (proto->hfid == -2) { /* Only free deregistered Proto */ g_free(proto); @@ -577,6 +699,9 @@ WSLUA_META Proto_meta[] = { int Proto_register(lua_State* L) { WSLUA_REGISTER_CLASS_WITH_ATTRS(Proto); + if (outstanding_FuncSavers != NULL) { + g_ptr_array_unref(outstanding_FuncSavers); + } outstanding_FuncSavers = g_ptr_array_new(); lua_newtable(L); @@ -624,9 +749,9 @@ int wslua_deregister_heur_dissectors(lua_State* L) { /* for each registered heur dissector do... */ lua_rawgeti(L, LUA_REGISTRYINDEX, lua_heur_dissectors_table_ref); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { - const gchar *listname = luaL_checkstring(L, -2); + const char *listname = luaL_checkstring(L, -2); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { - const gchar *proto_name = luaL_checkstring(L, -2); + const char *proto_name = luaL_checkstring(L, -2); int proto_id = proto_get_id_by_short_name(proto_name); heur_dissector_delete(listname, heur_dissect_lua, proto_id); } @@ -698,18 +823,18 @@ int wslua_deregister_protocols(lua_State* L) { lua_pop(L, 1); if (proto->hfa && proto->hfa->len) { - proto_add_deregistered_data(g_array_free(proto->hfa,FALSE)); + proto_add_deregistered_data(g_array_free(proto->hfa,false)); } else { - g_array_free(proto->hfa,TRUE); + g_array_free(proto->hfa,true); } /* No need for deferred deletion of subtree indexes */ - g_array_free(proto->etta,TRUE); + g_array_free(proto->etta,true); if (proto->eia && proto->eia->len) { - proto_add_deregistered_data(g_array_free(proto->eia,FALSE)); + proto_add_deregistered_data(g_array_free(proto->eia,false)); } else { - g_array_free(proto->eia,TRUE); + g_array_free(proto->eia,true); } proto->hfid = -2; /* Deregister Proto, freed in Proto__gc */ @@ -726,19 +851,24 @@ int Proto_commit(lua_State* L) { lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref); /* for each registered Proto protocol do... */ - for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 2)) { + for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) { /* lua_next() pop'ed the nil, pushed a table entry key at index=2, with value at index=3. In our case, the key is the Proto's name, and the value is the Proto object. - At next iteration, the value (Proto object) and ProtoExperts table will be pop'ed due - to lua_pop(L, 2), and when lua_next() returns 0 (no more table entries), it will have + At next iteration, the value (Proto object) will be pop'ed due + to lua_pop(L, 1), and when lua_next() returns 0 (no more table entries), it will have pop'ed the final key itself, leaving just the protocols_table_ref table on the stack. */ Proto proto = checkProto(L,3); - gint* ettp = NULL; + int* ettp = NULL; - proto->hfa = g_array_new(TRUE,TRUE,sizeof(hf_register_info)); - proto->etta = g_array_new(TRUE,TRUE,sizeof(gint*)); - proto->eia = g_array_new(TRUE,TRUE,sizeof(ei_register_info)); + if (proto->hfa) { + /* This proto's ProtoFields were already registered. */ + continue; + } + + proto->hfa = g_array_new(true,true,sizeof(hf_register_info)); + proto->etta = g_array_new(true,true,sizeof(int*)); + proto->eia = g_array_new(true,true,sizeof(ei_register_info)); ettp = &(proto->ett); g_array_append_val(proto->etta,ettp); @@ -753,31 +883,19 @@ int Proto_commit(lua_State* L) { continue; } ProtoField f = checkProtoField(L,6); - hf_register_info hfri = { NULL, { NULL, NULL, FT_NONE, 0, NULL, 0, NULL, HFILL } }; - ettp = &(f->ett); - - hfri.p_id = &(f->hfid); - hfri.hfinfo.name = f->name; - hfri.hfinfo.abbrev = f->abbrev; - hfri.hfinfo.type = f->type; - hfri.hfinfo.display = f->base; - hfri.hfinfo.strings = VALS(f->vs); - hfri.hfinfo.bitmask = f->mask; - hfri.hfinfo.blurb = f->blob; - - // XXX this will leak resources. - if (f->hfid != -2) { + + // XXX this will leak resources on error + // If this continued and registered the field array, it wouldn't + // leak. We could perhaps print a warning or even err after + // registration. + if (!Proto_append_ProtoField(proto, f)) { return luaL_error(L,"%s is already registered; fields can be registered only once", f->abbrev); } - - f->hfid = -1; - g_array_append_val(proto->hfa,hfri); - g_array_append_val(proto->etta,ettp); } /* register the proto fields */ proto_register_field_array(proto->hfid,(hf_register_info*)(void*)proto->hfa->data,proto->hfa->len); - proto_register_subtree_array((gint**)(void*)proto->etta->data,proto->etta->len); + proto_register_subtree_array((int**)(void*)proto->etta->data,proto->etta->len); lua_pop(L,1); /* pop the table of ProtoFields */ @@ -793,25 +911,16 @@ int Proto_commit(lua_State* L) { continue; } ProtoExpert e = checkProtoExpert(L,6); - ei_register_info eiri = { NULL, { NULL, 0, 0, NULL, EXPFILL } }; - - eiri.ids = &(e->ids); - eiri.eiinfo.name = e->abbrev; - eiri.eiinfo.group = e->group; - eiri.eiinfo.severity = e->severity; - eiri.eiinfo.summary = e->text; - - if (e->ids.ei != EI_INIT_EI || e->ids.hf != -2) { + if (!Proto_append_ProtoExpert(proto, e)) { return luaL_error(L,"%s is already registered; expert fields can be registered only once", e->abbrev); } - - e->ids.hf = -1; - g_array_append_val(proto->eia,eiri); } expert_register_field_array(proto->expert_module, (ei_register_info*)(void*)proto->eia->data, proto->eia->len); - /* Proto object and ProtoFields table will be pop'ed by lua_pop(L, 2) in for statement */ + lua_pop(L,1); /* pop the table of ProtoExperts */ + + /* Proto object will be pop'ed by lua_pop(L, 1) in for statement */ } lua_pop(L,1); /* pop the protocols_table_ref */ @@ -819,7 +928,7 @@ int Proto_commit(lua_State* L) { return 0; } -static guint +static unsigned wslua_dissect_tcp_get_pdu_len(packet_info *pinfo, tvbuff_t *tvb, int offset, void *data) { @@ -843,7 +952,7 @@ wslua_dissect_tcp_get_pdu_len(packet_info *pinfo, tvbuff_t *tvb, /* if the Lua dissector reported the consumed bytes, pass it to our caller */ if (lua_isnumber(L, -1)) { /* we got the pdu_len */ - pdu_len = wslua_togint(L, -1); + pdu_len = wslua_toint(L, -1); lua_pop(L, 1); } else { THROW_LUA_ERROR("Lua Error dissect_tcp_pdus: get_len_func did not return a Lua number of the PDU length"); @@ -882,7 +991,7 @@ wslua_dissect_tcp_dissector(tvbuff_t *tvb, packet_info *pinfo, /* if the Lua dissector reported the consumed bytes, pass it to our caller */ if (lua_isnumber(L, -1)) { /* we got the consumed bytes or the missing bytes as a negative number */ - consumed_bytes = wslua_togint(L, -1); + consumed_bytes = wslua_toint(L, -1); lua_pop(L, 1); } } @@ -908,8 +1017,6 @@ WSLUA_FUNCTION wslua_dissect_tcp_pdus(lua_State* L) { their protocol's messages (i.e., their protocol data unit (PDU)). This function shouild not be used for protocols whose PDU length cannot be determined from a fixed minimum portion, such as HTTP or Telnet. - - @since 1.99.2 */ #define WSLUA_ARG_dissect_tcp_pdus_TVB 1 /* The Tvb buffer to dissect PDUs from. */ #define WSLUA_ARG_dissect_tcp_pdus_TREE 2 /* The Tvb buffer to dissect PDUs from. */ @@ -933,8 +1040,8 @@ WSLUA_FUNCTION wslua_dissect_tcp_pdus(lua_State* L) { crossing TCP segment boundaries or not. (default=true) */ Tvb tvb = checkTvb(L,WSLUA_ARG_dissect_tcp_pdus_TVB); TreeItem ti = checkTreeItem(L,WSLUA_ARG_dissect_tcp_pdus_TREE); - guint fixed_len = (guint)luaL_checkinteger(L,WSLUA_ARG_dissect_tcp_pdus_MIN_HEADER_SIZE); - gboolean proto_desegment = wslua_optbool(L, WSLUA_OPTARG_dissect_tcp_pdus_DESEGMENT, TRUE); + unsigned fixed_len = (unsigned)luaL_checkinteger(L,WSLUA_ARG_dissect_tcp_pdus_MIN_HEADER_SIZE); + bool proto_desegment = wslua_optbool(L, WSLUA_OPTARG_dissect_tcp_pdus_DESEGMENT, true); if (!lua_pinfo) { luaL_error(L,"dissect_tcp_pdus can only be invoked while in a dissect function"); diff --git a/epan/wslua/wslua_proto_expert.c b/epan/wslua/wslua_proto_expert.c index a7c7c82a..0cd2f8ad 100644 --- a/epan/wslua/wslua_proto_expert.c +++ b/epan/wslua/wslua_proto_expert.c @@ -24,35 +24,40 @@ WSLUA_CLASS_DEFINE(ProtoExpert,FAIL_ON_NULL("null ProtoExpert")); - /* A Protocol expert info field, to be used when adding items to the dissection tree. - - @since 1.11.3 - */ + /* A Protocol expert info field, to be used when adding items to the dissection tree. */ WSLUA_CONSTRUCTOR ProtoExpert_new(lua_State* L) { - /* Creates a new `ProtoExpert` object to be used for a protocol's expert information notices. - - @since 1.11.3 - */ + /* Creates a new `ProtoExpert` object to be used for a protocol's expert information notices. */ #define WSLUA_ARG_ProtoExpert_new_ABBR 1 /* Filter name of the expert info field (the string that is used in filters). */ #define WSLUA_ARG_ProtoExpert_new_TEXT 2 /* The default text of the expert field. */ -#define WSLUA_ARG_ProtoExpert_new_GROUP 3 /* Expert group type: one of: `expert.group.CHECKSUM`, - `expert.group.SEQUENCE`, `expert.group.RESPONSE_CODE`, - `expert.group.REQUEST_CODE`, `expert.group.UNDECODED`, - `expert.group.REASSEMBLE`, `expert.group.MALFORMED`, - `expert.group.DEBUG`, `expert.group.PROTOCOL`, - `expert.group.SECURITY`, `expert.group.COMMENTS_GROUP`, - `expert.group.DECRYPTION`, `expert.group.ASSUMPTION` - or `expert.group.DEPRECATED`. */ +#define WSLUA_ARG_ProtoExpert_new_GROUP 3 /* Expert group type: one of: + `expert.group.CHECKSUM`, + `expert.group.SEQUENCE`, + `expert.group.RESPONSE_CODE`, + `expert.group.REQUEST_CODE`, + `expert.group.UNDECODED`, + `expert.group.REASSEMBLE`, + `expert.group.MALFORMED`, + `expert.group.DEBUG`, + `expert.group.PROTOCOL`, + `expert.group.SECURITY`, + `expert.group.COMMENTS_GROUP`, + `expert.group.DECRYPTION`, + `expert.group.ASSUMPTION`, + `expert.group.DEPRECATED`, + `expert.group.RECEIVE`, + or `expert.group.INTERFACE`. */ #define WSLUA_ARG_ProtoExpert_new_SEVERITY 4 /* Expert severity type: one of: - `expert.severity.COMMENT`, `expert.severity.CHAT`, - `expert.severity.NOTE`, `expert.severity.WARN`, + `expert.severity.COMMENT`, + `expert.severity.CHAT`, + `expert.severity.NOTE`, + `expert.severity.WARN`, or `expert.severity.ERROR`. */ ProtoExpert pe = NULL; - const gchar* abbr = wslua_checkstring_only(L,WSLUA_ARG_ProtoExpert_new_ABBR); - const gchar* text = wslua_checkstring_only(L,WSLUA_ARG_ProtoExpert_new_TEXT); + const char* abbr = wslua_checkstring_only(L,WSLUA_ARG_ProtoExpert_new_ABBR); + const char* text = wslua_checkstring_only(L,WSLUA_ARG_ProtoExpert_new_TEXT); int group = (int)luaL_checkinteger(L, WSLUA_ARG_ProtoExpert_new_GROUP); int severity = (int)luaL_checkinteger(L, WSLUA_ARG_ProtoExpert_new_SEVERITY); @@ -91,6 +96,9 @@ WSLUA_CONSTRUCTOR ProtoExpert_new(lua_State* L) { case PI_DECRYPTION: case PI_ASSUMPTION: case PI_DEPRECATED: + case PI_RECEIVE: + case PI_INTERFACE: + case PI_DISSECTOR_BUG: break; default: luaL_argerror(L, WSLUA_ARG_ProtoExpert_new_GROUP, "Group must be one of expert.group.*"); @@ -124,10 +132,7 @@ WSLUA_CONSTRUCTOR ProtoExpert_new(lua_State* L) { } WSLUA_METAMETHOD ProtoExpert__tostring(lua_State* L) { - /* Returns a string with debugging information about a `ProtoExpert` object. - - @since 1.11.3 - */ + /* Returns a string with debugging information about a `ProtoExpert` object. */ ProtoExpert pe = toProtoExpert(L,1); if (!pe) { @@ -153,8 +158,8 @@ static int ProtoExpert__gc(lua_State* L) { return 0; } - g_free((gchar *)pe->abbrev); - g_free((gchar *)pe->text); + g_free((char *)pe->abbrev); + g_free((char *)pe->text); g_free(pe); return 0; diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c index 86f3652e..ef180962 100644 --- a/epan/wslua/wslua_proto_field.c +++ b/epan/wslua/wslua_proto_field.c @@ -17,6 +17,9 @@ #include "config.h" +#include <epan/tfs.h> +#include <epan/unit_strings.h> + #include "wslua.h" /* WSLUA_CONTINUE_MODULE Proto */ @@ -61,7 +64,7 @@ static const wslua_ft_types_t ftenums[] = { {NULL, FT_NONE} }; -static enum ftenum get_ftenum(const gchar* type) { +static enum ftenum get_ftenum(const char* type) { const wslua_ft_types_t* ts; for (ts = ftenums; ts->str; ts++) { if ( g_str_equal(ts->str,type) ) { @@ -71,7 +74,7 @@ static enum ftenum get_ftenum(const gchar* type) { return FT_NONE; } -static const gchar* ftenum_to_string(enum ftenum ft) { +static const char* ftenum_to_string(enum ftenum ft) { const wslua_ft_types_t* ts; for (ts = ftenums; ts->str; ts++) { if ( ts->id == ft ) { @@ -82,7 +85,7 @@ static const gchar* ftenum_to_string(enum ftenum ft) { } struct field_display_string_t { - const gchar* str; + const char* str; unsigned base; }; @@ -119,7 +122,7 @@ static const struct field_display_string_t base_displays[] = { {NULL,0} }; -static const gchar* base_to_string(unsigned base) { +static const char* base_to_string(unsigned base) { const struct field_display_string_t* b; for (b=base_displays;b->str;b++) { if ( base == b->base) @@ -128,7 +131,7 @@ static const gchar* base_to_string(unsigned base) { return NULL; } -static unsigned string_to_base(const gchar* str) { +static unsigned string_to_base(const char* str) { const struct field_display_string_t* b; for (b=base_displays;b->str;b++) { if ( g_str_equal(str,b->str)) @@ -141,10 +144,10 @@ static void cleanup_range_string(GArray *rs) { range_string *rs32 = (range_string *)(void *)(rs->data); while (rs32->strptr) { - g_free((gchar *)rs32->strptr); + g_free((char *)rs32->strptr); rs32++; } - g_array_free(rs, TRUE); + g_array_free(rs, true); } static range_string * range_string_from_table(lua_State* L, int idx) { @@ -159,10 +162,10 @@ static range_string * range_string_from_table(lua_State* L, int idx) { } /* - * The first parameter set to TRUE means give us a zero-filled + * The first parameter set to true means give us a zero-filled * terminal entry. */ - rs = g_array_new(TRUE,TRUE,sizeof(range_string)); + rs = g_array_new(true,true,sizeof(range_string)); lua_pushnil(L); @@ -204,9 +207,9 @@ static range_string * range_string_from_table(lua_State* L, int idx) { return NULL; } if (key_count == 1) /* We incremented it above */ - r.value_min = wslua_toguint64(L, -1); + r.value_min = wslua_touint64(L, -1); else - r.value_max = wslua_toguint64(L, -1); + r.value_max = wslua_touint64(L, -1); break; case 3: @@ -236,7 +239,7 @@ static range_string * range_string_from_table(lua_State* L, int idx) { lua_pop(L, 1); } - rs32 = (range_string*)(void*)g_array_free(rs, FALSE); + rs32 = (range_string*)(void*)g_array_free(rs, false); return rs32; } @@ -253,10 +256,10 @@ static value_string* value_string_from_table(lua_State* L, int idx) { } /* - * The first parameter set to TRUE means give us a zero-filled + * The first parameter set to true means give us a zero-filled * terminal entry. */ - vs = g_array_new(TRUE,TRUE,sizeof(value_string)); + vs = g_array_new(true,true,sizeof(value_string)); lua_pushnil(L); @@ -266,10 +269,10 @@ static value_string* value_string_from_table(lua_State* L, int idx) { if (! lua_isnumber(L,-2)) { vs32 = (value_string *)(void *)vs->data; while (vs32->strptr) { - g_free((gchar *)vs32->strptr); + g_free((char *)vs32->strptr); vs32++; } - g_array_free(vs,TRUE); + g_array_free(vs,true); luaL_argerror(L,idx,"All keys of a table used as value_string must be integers"); return NULL; } @@ -277,15 +280,15 @@ static value_string* value_string_from_table(lua_State* L, int idx) { if (! lua_isstring(L,-1)) { vs32 = (value_string *)(void *)vs->data; while (vs32->strptr) { - g_free((gchar *)vs32->strptr); + g_free((char *)vs32->strptr); vs32++; } - g_array_free(vs,TRUE); + g_array_free(vs,true); luaL_argerror(L,idx,"All values of a table used as value_string must be strings"); return NULL; } - v.value = wslua_toguint32(L,-2); + v.value = wslua_touint32(L,-2); v.strptr = g_strdup(lua_tostring(L,-1)); g_array_append_val(vs,v); @@ -293,7 +296,7 @@ static value_string* value_string_from_table(lua_State* L, int idx) { lua_pop(L, 1); } - vs32 = (value_string*)(void*)g_array_free(vs, FALSE); + vs32 = (value_string*)(void*)g_array_free(vs, false); return vs32; } @@ -310,10 +313,10 @@ static val64_string* val64_string_from_table(lua_State* L, int idx) { } /* - * The first parameter set to TRUE means give us a zero-filled + * The first parameter set to true means give us a zero-filled * terminal entry. */ - vs = g_array_new(TRUE,TRUE,sizeof(val64_string)); + vs = g_array_new(true,true,sizeof(val64_string)); lua_pushnil(L); @@ -323,10 +326,10 @@ static val64_string* val64_string_from_table(lua_State* L, int idx) { if (! lua_isnumber(L,-2)) { vs64 = (val64_string *)(void *)vs->data; while (vs64->strptr) { - g_free((gchar *)vs64->strptr); + g_free((char *)vs64->strptr); vs64++; } - g_array_free(vs,TRUE); + g_array_free(vs,true); luaL_argerror(L,idx,"All keys of a table used as value string must be integers"); return NULL; } @@ -334,15 +337,15 @@ static val64_string* val64_string_from_table(lua_State* L, int idx) { if (! lua_isstring(L,-1)) { vs64 = (val64_string *)(void *)vs->data; while (vs64->strptr) { - g_free((gchar *)vs64->strptr); + g_free((char *)vs64->strptr); vs64++; } - g_array_free(vs,TRUE); + g_array_free(vs,true); luaL_argerror(L,idx,"All values of a table used as value string must be strings"); return NULL; } - v.value = wslua_toguint64(L, -2); + v.value = wslua_touint64(L, -2); v.strptr = g_strdup(lua_tostring(L,-1)); g_array_append_val(vs,v); @@ -350,15 +353,15 @@ static val64_string* val64_string_from_table(lua_State* L, int idx) { lua_pop(L, 1); } - vs64 = (val64_string*)(void*)g_array_free(vs, FALSE); + vs64 = (val64_string*)(void*)g_array_free(vs, false); return vs64; } static true_false_string* true_false_string_from_table(lua_State* L, int idx) { true_false_string* tfs; - gchar *true_string; - gchar *false_string; + char *true_string; + char *false_string; if (lua_isnil(L,idx)) { return NULL; @@ -415,12 +418,12 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) { return tfs; } -static guint64 get_mask(lua_State* L, int idx, guint64 default_value) { - guint64 mask = default_value; +static uint64_t get_mask(lua_State* L, int idx, uint64_t default_value) { + uint64_t mask = default_value; switch(lua_type(L, idx)) { case LUA_TNUMBER: - mask = (guint64)wslua_optguint32(L, idx, (lua_Number)default_value); + mask = (uint64_t)wslua_optuint32(L, idx, (lua_Number)default_value); break; case LUA_TSTRING: case LUA_TUSERDATA: @@ -471,11 +474,11 @@ static unit_name_string* unit_name_string_from_table(lua_State* L, int idx) { /* Arrays in Lua start with index number 1 */ switch (lua_tointeger(L,-2)) { case 1: - g_free((gchar *)units->singular); + g_free((char *)units->singular); units->singular = g_strdup(lua_tostring(L,-1)); break; case 2: - g_free((gchar *)units->plural); + g_free((char *)units->plural); units->plural = g_strdup(lua_tostring(L,-1)); break; default: @@ -499,8 +502,8 @@ static unit_name_string* unit_name_string_from_table(lua_State* L, int idx) { return units; } -static const gchar* check_field_name(lua_State* L, const int abbr_idx, const enum ftenum type) { - const gchar* abbr = luaL_checkstring(L,abbr_idx); +static const char* check_field_name(lua_State* L, const int abbr_idx, const enum ftenum type) { + const char* abbr = luaL_checkstring(L,abbr_idx); const header_field_info* hfinfo = NULL; if (!abbr[0]) { @@ -548,12 +551,12 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { `base.HEX_DEC`, `base.UNIT_STRING` or `base.RANGE_STRING`. */ #define WSLUA_OPTARG_ProtoField_new_MASK 6 /* The bitmask to be used. */ -#define WSLUA_OPTARG_ProtoField_new_DESCR 7 /* The description of the field. */ +#define WSLUA_OPTARG_ProtoField_new_DESCRIPTION 7 /* The description of the field. */ ProtoField f; int nargs = lua_gettop(L); - const gchar* name = luaL_checkstring(L,WSLUA_ARG_ProtoField_new_NAME); - const gchar* abbr = NULL; + const char* name = luaL_checkstring(L,WSLUA_ARG_ProtoField_new_NAME); + const char* abbr = NULL; enum ftenum type; enum ft_framenum_type framenum_type = FT_FRAMENUM_NONE; range_string *rs32 = NULL; @@ -562,10 +565,10 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { true_false_string *tfs = NULL; unit_name_string *uns = NULL; unsigned base; - guint64 mask = get_mask(L,WSLUA_OPTARG_ProtoField_new_MASK, 0x0); - const gchar *blob = luaL_optstring(L,WSLUA_OPTARG_ProtoField_new_DESCR,NULL); - gboolean base_unit_string = FALSE; - gboolean base_range_string = FALSE; + uint64_t mask = get_mask(L,WSLUA_OPTARG_ProtoField_new_MASK, 0x0); + const char *blob = luaL_optstring(L,WSLUA_OPTARG_ProtoField_new_DESCRIPTION,NULL); + bool base_unit_string = false; + bool base_range_string = false; if (!name[0]) { WSLUA_ARG_ERROR(ProtoField_new,NAME,"cannot be an empty string"); @@ -624,11 +627,11 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { case FT_INT32: case FT_INT64: if (base & BASE_UNIT_STRING) { - base_unit_string = TRUE; + base_unit_string = true; base &= ~BASE_UNIT_STRING; } if (base & BASE_RANGE_STRING) { - base_range_string = TRUE; + base_range_string = true; base &= ~BASE_RANGE_STRING; } if (base_unit_string && base_range_string) { @@ -719,7 +722,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { case FT_FLOAT: case FT_DOUBLE: if (base & BASE_UNIT_STRING) { - base_unit_string = TRUE; + base_unit_string = true; base &= ~BASE_UNIT_STRING; } if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING) { @@ -806,6 +809,12 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { } else { f->vs = NULL; } + if (f->vs) { + lua_pushvalue(L, WSLUA_OPTARG_ProtoField_new_VALUESTRING); + f->valuestring_ref = luaL_ref(L, LUA_REGISTRYINDEX); + } else { + f->valuestring_ref = LUA_NOREF; + } f->mask = mask; if (blob && strcmp(blob, f->name) != 0) { f->blob = g_strdup(blob); @@ -820,8 +829,8 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { static int ProtoField_integer(lua_State* L, enum ftenum type) { ProtoField f; - const gchar* abbr = check_field_name(L,1,type); - const gchar* name = luaL_optstring(L,2,abbr); + const char* abbr = check_field_name(L,1,type); + const char* name = luaL_optstring(L,2,abbr); unsigned default_base = (type == FT_FRAMENUM) ? BASE_NONE : ((type == FT_CHAR) ? BASE_OCT : BASE_DEC); unsigned base = (unsigned)luaL_optinteger(L, 3, default_base); enum ft_framenum_type framenum_type = FT_FRAMENUM_NONE; @@ -829,10 +838,10 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { range_string* rs32 = NULL; val64_string* vs64 = NULL; unit_name_string* uns = NULL; - guint64 mask = get_mask(L,5,0); - const gchar* blob = luaL_optstring(L,6,NULL); - gboolean base_unit_string = FALSE; - gboolean base_range_string = FALSE; + uint64_t mask = get_mask(L,5,0); + const char* blob = luaL_optstring(L,6,NULL); + bool base_unit_string = false; + bool base_range_string = false; if (!name[0]) { luaL_argerror(L, 2, "cannot be an empty string"); @@ -845,7 +854,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { } if (base & BASE_UNIT_STRING) { - base_unit_string = TRUE; + base_unit_string = true; base &= ~BASE_UNIT_STRING; if (base == BASE_NONE) { base = BASE_DEC; @@ -853,7 +862,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { } if (base & BASE_RANGE_STRING) { - base_range_string = TRUE; + base_range_string = true; base &= ~BASE_RANGE_STRING; if (type != FT_CHAR && base == BASE_NONE) { base = BASE_DEC; @@ -942,6 +951,12 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { } else { f->vs = NULL; } + if (f->vs) { + lua_pushvalue(L, 4); + f->valuestring_ref = luaL_ref(L, LUA_REGISTRYINDEX); + } else { + f->valuestring_ref = LUA_NOREF; + } f->mask = mask; if (blob && strcmp(blob, f->name) != 0) { f->blob = g_strdup(blob); @@ -961,7 +976,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_char_BASE One of `base.NONE`, `base.HEX`, `base.OCT` or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_char_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_char_MASK Integer mask of this field. */ -/* WSLUA_OPTARG_ProtoField_char_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_char_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_uint8 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 8-bit integer (i.e., a byte). */ @@ -970,7 +985,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint8_BASE One of `base.DEC`, `base.HEX` or `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING` or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint8_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint8_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_uint8_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_uint8_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_uint16 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 16-bit integer. */ @@ -979,7 +994,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint16_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING` or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint16_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint16_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_uint16_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_uint16_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_uint24 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 24-bit integer. */ @@ -988,7 +1003,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint24_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint24_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint24_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_uint24_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_uint24_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_uint32 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 32-bit integer. */ @@ -997,7 +1012,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint32_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint32_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint32_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_uint32_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_uint32_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_uint64 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 64-bit integer. */ @@ -1006,7 +1021,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint64_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint64_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint64_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_uint64_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_uint64_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_int8 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 8-bit integer (i.e., a byte). */ @@ -1015,7 +1030,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int8_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int8_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_int8_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_int8_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_int8_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_int16 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 16-bit integer. */ @@ -1024,7 +1039,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int16_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int16_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_int16_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_int16_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_int16_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_int24 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 24-bit integer. */ @@ -1033,7 +1048,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int24_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int24_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_int24_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_int24_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_int24_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_int32 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 32-bit integer. */ @@ -1042,7 +1057,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int32_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int32_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_int32_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_int32_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_int32_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_int64 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 64-bit integer. */ @@ -1051,7 +1066,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int64_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int64_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ /* WSLUA_OPTARG_ProtoField_int64_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_int64_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_int64_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_framenum Creates a <<lua_class_ProtoField,`ProtoField`>> for a frame number (for hyperlinks between frames). */ @@ -1060,7 +1075,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_framenum_BASE Only `base.NONE` is supported for framenum. */ /* WSLUA_OPTARG_ProtoField_framenum_FRAMETYPE One of `frametype.NONE`, `frametype.REQUEST`, `frametype.RESPONSE`, `frametype.ACK` or `frametype.DUP_ACK`. */ /* WSLUA_OPTARG_ProtoField_framenum_MASK Integer, String or UInt64 mask of this field, which must be 0 for framenum. */ -/* WSLUA_OPTARG_ProtoField_framenum_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_framenum_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ PROTOFIELD_INTEGER(char,FT_CHAR) @@ -1078,12 +1093,12 @@ PROTOFIELD_INTEGER(framenum,FT_FRAMENUM) static int ProtoField_boolean(lua_State* L, enum ftenum type) { ProtoField f; - const gchar* abbr = check_field_name(L,1,type); - const gchar* name = luaL_optstring(L,2,abbr); + const char* abbr = check_field_name(L,1,type); + const char* name = luaL_optstring(L,2,abbr); unsigned base = (unsigned)luaL_optinteger(L, 3, BASE_NONE); true_false_string* tfs = NULL; - guint64 mask = get_mask(L,5,0); - const gchar* blob = luaL_optstring(L,6,NULL); + uint64_t mask = get_mask(L,5,0); + const char* blob = luaL_optstring(L,6,NULL); if (!name[0]) { luaL_argerror(L, 2, "cannot be an empty string"); @@ -1113,8 +1128,14 @@ static int ProtoField_boolean(lua_State* L, enum ftenum type) { f->name = g_strdup(name); f->abbrev = g_strdup(abbr); f->type = type; - f->vs = TFS(tfs); f->base = base; + f->vs = TFS(tfs); + if (f->vs) { + lua_pushvalue(L, 4); + f->valuestring_ref = luaL_ref(L, LUA_REGISTRYINDEX); + } else { + f->valuestring_ref = LUA_NOREF; + } f->mask = mask; if (blob && strcmp(blob, f->name) != 0) { f->blob = g_strdup(blob); @@ -1134,17 +1155,17 @@ static int ProtoField_boolean(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_bool_DISPLAY How wide the parent bitfield is (`base.NONE` is used for NULL-value). */ /* WSLUA_OPTARG_ProtoField_bool_VALUESTRING A table containing the text that corresponds to the values. */ /* WSLUA_OPTARG_ProtoField_bool_MASK Integer, String or UInt64 mask of this field. */ -/* WSLUA_OPTARG_ProtoField_bool_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_bool_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ PROTOFIELD_BOOL(bool,FT_BOOLEAN) static int ProtoField_time(lua_State* L,enum ftenum type) { ProtoField f; - const gchar* abbr = check_field_name(L,1,type); - const gchar* name = luaL_optstring(L,2,abbr); + const char* abbr = check_field_name(L,1,type); + const char* name = luaL_optstring(L,2,abbr); unsigned base = (unsigned)luaL_optinteger(L,3,ABSOLUTE_TIME_LOCAL); - const gchar* blob = luaL_optstring(L,4,NULL); + const char* blob = luaL_optstring(L,4,NULL); if (!name[0]) { luaL_argerror(L, 2, "cannot be an empty string"); @@ -1165,8 +1186,9 @@ static int ProtoField_time(lua_State* L,enum ftenum type) { f->name = g_strdup(name); f->abbrev = g_strdup(abbr); f->type = type; - f->vs = NULL; f->base = base; + f->vs = NULL; + f->valuestring_ref = LUA_NOREF; f->mask = 0; if (blob && strcmp(blob, f->name) != 0) { f->blob = g_strdup(blob); @@ -1184,13 +1206,13 @@ static int ProtoField_time(lua_State* L,enum ftenum type) { /* WSLUA_ARG_ProtoField_absolute_time_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_absolute_time_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_absolute_time_BASE One of `base.LOCAL`, `base.UTC` or `base.DOY_UTC`. */ -/* WSLUA_OPTARG_ProtoField_absolute_time_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_absolute_time_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_relative_time Creates a <<lua_class_ProtoField,`ProtoField`>> of a time_t structure value. */ /* WSLUA_ARG_ProtoField_relative_time_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_relative_time_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_relative_time_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_relative_time_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -1198,10 +1220,10 @@ PROTOFIELD_TIME(absolute_time,FT_ABSOLUTE_TIME) static int ProtoField_floating(lua_State* L,enum ftenum type) { ProtoField f; - const gchar* abbr = check_field_name(L,1,type); - const gchar* name = luaL_optstring(L,2,abbr); + const char* abbr = check_field_name(L,1,type); + const char* name = luaL_optstring(L,2,abbr); unit_name_string* uns = NULL; - const gchar* blob; + const char* blob; if (!name[0]) { luaL_argerror(L, 2, "cannot be an empty string"); @@ -1223,11 +1245,14 @@ static int ProtoField_floating(lua_State* L,enum ftenum type) { f->abbrev = g_strdup(abbr); f->type = type; if (uns) { - f->vs = uns; f->base = BASE_NONE | BASE_UNIT_STRING; + f->vs = uns; + lua_pushvalue(L, 3); + f->valuestring_ref = luaL_ref(L, LUA_REGISTRYINDEX); } else { - f->vs = NULL; f->base = BASE_NONE; + f->vs = NULL; + f->valuestring_ref = LUA_NOREF; } f->mask = 0; if (blob && strcmp(blob, f->name) != 0) { @@ -1246,14 +1271,14 @@ static int ProtoField_floating(lua_State* L,enum ftenum type) { /* WSLUA_ARG_ProtoField_float_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_float_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_float_VALUESTRING A table containing unit name for the values. */ -/* WSLUA_OPTARG_ProtoField_float_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_float_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_double Creates a <<lua_class_ProtoField,`ProtoField`>> of a double-precision floating point (8 bytes). */ /* WSLUA_ARG_ProtoField_double_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_double_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_double_VALUESTRING A table containing unit name for the values. */ -/* WSLUA_OPTARG_ProtoField_double_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_double_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ PROTOFIELD_FLOATING(float,FT_FLOAT) @@ -1261,10 +1286,10 @@ PROTOFIELD_FLOATING(double,FT_DOUBLE) static int ProtoField_other_display(lua_State* L,enum ftenum type) { ProtoField f; - const gchar* abbr = check_field_name(L,1,type); - const gchar* name = luaL_optstring(L,2,abbr); + const char* abbr = check_field_name(L,1,type); + const char* name = luaL_optstring(L,2,abbr); unsigned base = BASE_NONE; - const gchar* blob; + const char* blob; if (!name[0]) { luaL_argerror(L, 2, "cannot be an empty string"); @@ -1297,8 +1322,9 @@ static int ProtoField_other_display(lua_State* L,enum ftenum type) { f->name = g_strdup(name); f->abbrev = g_strdup(abbr); f->type = type; - f->vs = NULL; f->base = base; + f->vs = NULL; + f->valuestring_ref = LUA_NOREF; f->mask = 0; if (blob && strcmp(blob, f->name) != 0) { f->blob = g_strdup(blob); @@ -1316,28 +1342,28 @@ static int ProtoField_other_display(lua_State* L,enum ftenum type) { /* WSLUA_ARG_ProtoField_string_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_string_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_string_DISPLAY One of `base.ASCII` or `base.UNICODE`. */ -/* WSLUA_OPTARG_ProtoField_string_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_string_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_stringz Creates a <<lua_class_ProtoField,`ProtoField`>> of a zero-terminated string value. */ /* WSLUA_ARG_ProtoField_stringz_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_stringz_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_stringz_DISPLAY One of `base.ASCII` or `base.UNICODE`. */ -/* WSLUA_OPTARG_ProtoField_stringz_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_stringz_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_bytes Creates a <<lua_class_ProtoField,`ProtoField`>> for an arbitrary number of bytes. */ /* WSLUA_ARG_ProtoField_bytes_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_bytes_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_bytes_DISPLAY One of `base.NONE`, `base.DOT`, `base.DASH`, `base.COLON` or `base.SPACE`. */ -/* WSLUA_OPTARG_ProtoField_bytes_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_bytes_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_ubytes Creates a <<lua_class_ProtoField,`ProtoField`>> for an arbitrary number of unsigned bytes. */ /* WSLUA_ARG_ProtoField_ubytes_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_ubytes_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_ubytes_DISPLAY One of `base.NONE`, `base.DOT`, `base.DASH`, `base.COLON` or `base.SPACE`. */ -/* WSLUA_OPTARG_ProtoField_ubytes_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_ubytes_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ @@ -1348,9 +1374,9 @@ PROTOFIELD_OTHER_DISPLAY(ubytes,FT_UINT_BYTES) static int ProtoField_other(lua_State* L,enum ftenum type) { ProtoField f; - const gchar* abbr = check_field_name(L,1,type); - const gchar* name = luaL_optstring(L,2,abbr); - const gchar* blob = luaL_optstring(L,3,NULL); + const char* abbr = check_field_name(L,1,type); + const char* name = luaL_optstring(L,2,abbr); + const char* blob = luaL_optstring(L,3,NULL); if (!name[0]) { luaL_argerror(L, 2, "cannot be an empty string"); @@ -1364,8 +1390,9 @@ static int ProtoField_other(lua_State* L,enum ftenum type) { f->name = g_strdup(name); f->abbrev = g_strdup(abbr); f->type = type; - f->vs = NULL; f->base = BASE_NONE; + f->vs = NULL; + f->valuestring_ref = LUA_NOREF; f->mask = 0; if (blob && strcmp(blob, f->name) != 0) { f->blob = g_strdup(blob); @@ -1382,61 +1409,61 @@ static int ProtoField_other(lua_State* L,enum ftenum type) { /* _WSLUA_CONSTRUCTOR_ ProtoField_none Creates a <<lua_class_ProtoField,`ProtoField`>> of an unstructured type. */ /* WSLUA_ARG_ProtoField_none_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_none_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_none_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_none_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_ipv4 Creates a <<lua_class_ProtoField,`ProtoField`>> of an IPv4 address (4 bytes). */ /* WSLUA_ARG_ProtoField_ipv4_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_ipv4_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_ipv4_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_ipv4_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_ipv6 Creates a <<lua_class_ProtoField,`ProtoField`>> of an IPv6 address (16 bytes). */ /* WSLUA_ARG_ProtoField_ipv6_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_ipv6_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_ipv6_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_ipv6_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_ether Creates a <<lua_class_ProtoField,`ProtoField`>> of an Ethernet address (6 bytes). */ /* WSLUA_ARG_ProtoField_ether_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_ether_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_ether_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_ether_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_guid Creates a <<lua_class_ProtoField,`ProtoField`>> for a Globally Unique IDentifier (GUID). */ /* WSLUA_ARG_ProtoField_guid_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_guid_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_guid_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_guid_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_oid Creates a <<lua_class_ProtoField,`ProtoField`>> for an ASN.1 Organizational IDentified (OID). */ /* WSLUA_ARG_ProtoField_oid_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_oid_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_oid_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_oid_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ -/* _WSLUA_CONSTRUCTOR_ ProtoField_protocol Creates a <<lua_class_ProtoField,`ProtoField`>> for a sub-protocol. Since 1.99.9. */ +/* _WSLUA_CONSTRUCTOR_ ProtoField_protocol Creates a <<lua_class_ProtoField,`ProtoField`>> for a sub-protocol. */ /* WSLUA_ARG_ProtoField_protocol_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_protocol_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_protocol_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_protocol_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_rel_oid Creates a <<lua_class_ProtoField,`ProtoField`>> for an ASN.1 Relative-OID. */ /* WSLUA_ARG_ProtoField_rel_oid_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_rel_oid_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_rel_oid_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_rel_oid_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_systemid Creates a <<lua_class_ProtoField,`ProtoField`>> for an OSI System ID. */ /* WSLUA_ARG_ProtoField_systemid_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_systemid_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_systemid_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_systemid_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ /* _WSLUA_CONSTRUCTOR_ ProtoField_eui64 Creates a <<lua_class_ProtoField,`ProtoField`>> for an EUI64. */ /* WSLUA_ARG_ProtoField_eui64_ABBR Abbreviated name of the field (the string used in filters). */ /* WSLUA_OPTARG_ProtoField_eui64_NAME Actual name of the field (the string that appears in the tree). */ -/* WSLUA_OPTARG_ProtoField_eui64_DESC Description of the field. */ +/* WSLUA_OPTARG_ProtoField_eui64_DESCRIPTION Description of the field. */ /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */ PROTOFIELD_OTHER(none,FT_NONE) @@ -1452,10 +1479,60 @@ PROTOFIELD_OTHER(rel_oid,FT_REL_OID) PROTOFIELD_OTHER(systemid,FT_SYSTEM_ID) PROTOFIELD_OTHER(eui64,FT_EUI64) +/* WSLUA_ATTRIBUTE ProtoField_type RO The type of the field. + + @since 4.3.0 +*/ +WSLUA_ATTRIBUTE_INTEGER_GETTER(ProtoField,type); + +/* WSLUA_ATTRIBUTE ProtoField_abbr RO The abbreviated name of the field. + + @since 4.3.0 +*/ +WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(ProtoField,abbr,abbrev); + +/* WSLUA_ATTRIBUTE ProtoField_name RO The actual name of the field. + + @since 4.3.0 +*/ +WSLUA_ATTRIBUTE_STRING_GETTER(ProtoField,name); + +/* WSLUA_ATTRIBUTE ProtoField_base RO The base of the field. + + @since 4.3.0 +*/ +WSLUA_ATTRIBUTE_INTEGER_GETTER(ProtoField,base); + +/* WSLUA_ATTRIBUTE ProtoField_valuestring RO The valuestring of the field. + + @since 4.3.0 +*/ +WSLUA_METAMETHOD ProtoField_get_valuestring(lua_State* L) { + ProtoField f = checkProtoField(L,1); + if (f->valuestring_ref != LUA_NOREF) { + lua_rawgeti(L, LUA_REGISTRYINDEX, f->valuestring_ref); + } else { + lua_pushnil(L); + } + return 1; +} + +/* WSLUA_ATTRIBUTE ProtoField_mask RO The mask of the field. + + @since 4.3.0 +*/ +WSLUA_ATTRIBUTE_INTEGER_GETTER(ProtoField,mask); + +/* WSLUA_ATTRIBUTE ProtoField_description RO The description of this field. + + @since 4.3.0 +*/ +WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(ProtoField,description,blob); + WSLUA_METAMETHOD ProtoField__tostring(lua_State* L) { /* Returns a string with info about a protofield (for debugging purposes). */ ProtoField f = checkProtoField(L,1); - gchar* s = ws_strdup_printf("ProtoField(%i): %s %s %s %s %p %.16" PRIu64 "x %s", + char* s = ws_strdup_printf("ProtoField(%i): %s %s %s %s %p %.16" PRIu64 "x %s", f->hfid,f->name,f->abbrev, ftenum_to_string(f->type), base_to_string(f->base), @@ -1484,6 +1561,9 @@ static int ProtoField__gc(lua_State* L) { g_free(f->abbrev); g_free(f->blob); proto_free_field_strings(f->type, f->base, f->vs); + if (f->valuestring_ref != LUA_NOREF) { + luaL_unref(L, LUA_REGISTRYINDEX, f->valuestring_ref); + } g_free(f); return 0; @@ -1526,13 +1606,28 @@ WSLUA_METHODS ProtoField_methods[] = { { NULL, NULL } }; +/* This table is ultimately registered as a sub-table of the class' metatable, + * and if __index/__newindex is invoked then it calls the appropriate function + * from this table for getting/setting the members. + */ +WSLUA_ATTRIBUTES ProtoField_attributes[] = { + WSLUA_ATTRIBUTE_ROREG(ProtoField,type), + WSLUA_ATTRIBUTE_ROREG(ProtoField,abbr), + WSLUA_ATTRIBUTE_ROREG(ProtoField,name), + WSLUA_ATTRIBUTE_ROREG(ProtoField,base), + WSLUA_ATTRIBUTE_ROREG(ProtoField,valuestring), + WSLUA_ATTRIBUTE_ROREG(ProtoField,mask), + WSLUA_ATTRIBUTE_ROREG(ProtoField,description), + { NULL, NULL, NULL } +}; + WSLUA_META ProtoField_meta[] = { WSLUA_CLASS_MTREG(ProtoField,tostring), { NULL, NULL } }; int ProtoField_register(lua_State* L) { - WSLUA_REGISTER_CLASS(ProtoField); + WSLUA_REGISTER_CLASS_WITH_ATTRS(ProtoField); return 0; } diff --git a/epan/wslua/wslua_struct.c b/epan/wslua/wslua_struct.c index 7d62dc09..c1f6dc1b 100644 --- a/epan/wslua/wslua_struct.c +++ b/epan/wslua/wslua_struct.c @@ -60,13 +60,8 @@ #include "config.h" -#include <assert.h> #include <limits.h> -#include <stddef.h> -#include <string.h> - -#include <stdio.h> - +#include <wsutil/array.h> #include "wslua.h" /* WSLUA_MODULE Struct Binary encode/decode support @@ -131,7 +126,7 @@ * `++(++' to stop assigning items, and `++)++' start assigning (padding when packing). * `++=++' to return the current position / offset. - [NOTE] + [IMPORTANT] ==== Using `i`, `I`, `h`, `H`, `l`, `L`, `f`, and `T` is strongly discouraged, as those sizes are system-dependent. Use the explicitly sized variants instead, such as `i4` or `E`. @@ -141,7 +136,16 @@ Use `e`/`E` to unpack into a Wireshark `Int64`/`UInt64` object instead. ==== - @since 1.11.3 + [NOTE] + ==== + Lua 5.3 and later provides several built-in functions for struct unpacking and packing: + https://www.lua.org/manual/5.4/manual.html#pdf-string.pack[string.pack], + https://www.lua.org/manual/5.4/manual.html#pdf-string.packsize[string.packsize], and + https://www.lua.org/manual/5.4/manual.html#pdf-string.unpack[string.unpack]. + You can use those as well, but note that the + https://www.lua.org/manual/5.4/manual.html#6.4.2[format string] conversion elements + are slightly different, and they do not support the Wireshark `Int64`/`UInt64` objects. + ==== */ @@ -169,12 +173,12 @@ typedef unsigned STRUCT_INT Uinttype; /* dummy structure to get padding/alignment requirements */ struct cD { - gchar c; - gdouble d; + char c; + double d; }; -#define PADDING (sizeof(struct cD) - sizeof(gdouble)) +#define PADDING (sizeof(struct cD) - sizeof(double)) #define MAXALIGN (PADDING > sizeof(int) ? PADDING : sizeof(int)) @@ -185,23 +189,25 @@ struct cD { /* trick to determine native endianness of system */ static union { int dummy; - gchar endian; + char endian; } const native = {1}; /* settings info */ typedef struct Header { int endian; int align; - gboolean noassign; + bool noassign; } Header; /* For options that take a number argument, gets the number */ -static int getnum (const gchar **fmt, int df) { +static int getnum (lua_State *L, const char **fmt, int df) { if (!g_ascii_isdigit(**fmt)) /* no number? */ return df; /* return default value */ else { int a = 0; do { + if (a > (INT_MAX / 10) || a * 10 > (INT_MAX - (**fmt - '0'))) + luaL_error(L, "integral size overflow"); a = a*10 + *((*fmt)++) - '0'; } while (g_ascii_isdigit(**fmt)); return a; @@ -209,24 +215,24 @@ static int getnum (const gchar **fmt, int df) { } -#define defaultoptions(h) ((h)->endian = native.endian, (h)->align = 1, (h)->noassign = FALSE) +#define defaultoptions(h) ((h)->endian = native.endian, (h)->align = 1, (h)->noassign = false) /* gets size (number of bytes) for a given type */ -static size_t optsize (lua_State *L, gchar opt, const gchar **fmt) { +static size_t optsize (lua_State *L, char opt, const char **fmt) { switch (opt) { - case 'B': case 'b': return sizeof(gchar); - case 'H': case 'h': return sizeof(gshort); - case 'L': case 'l': return sizeof(glong); - case 'E': case 'e': return sizeof(gint64); + case 'B': case 'b': return sizeof(char); + case 'H': case 'h': return sizeof(short); + case 'L': case 'l': return sizeof(long); + case 'E': case 'e': return sizeof(int64_t); case 'T': return sizeof(size_t); - case 'f': return sizeof(gfloat); - case 'd': return sizeof(gdouble); - case 'x': return getnum(fmt, 1); - case 'X': return getnum(fmt, MAXALIGN); - case 'c': return getnum(fmt, 1); + case 'f': return sizeof(float); + case 'd': return sizeof(double); + case 'x': return getnum(L, fmt, 1); + case 'X': return getnum(L, fmt, MAXALIGN); + case 'c': return getnum(L, fmt, 1); case 'i': case 'I': { - int sz = getnum(fmt, sizeof(int)); + int sz = getnum(L, fmt, sizeof(int)); if (sz > MAXINTSIZE) luaL_error(L, "integral size %d is larger than limit of %d", sz, MAXINTSIZE); @@ -238,7 +244,7 @@ static size_t optsize (lua_State *L, gchar opt, const gchar **fmt) { case '!': case '=': return 0; /* these cases do not have a size */ default: { - const gchar *msg = lua_pushfstring(L, "invalid format option [%c]", opt); + const char *msg = lua_pushfstring(L, "invalid format option [%c]", opt); return luaL_argerror(L, 1, msg); } } @@ -260,16 +266,16 @@ static int gettoalign (size_t len, Header *h, int opt, size_t size) { /* ** options to control endianness and alignment settings */ -static void controloptions (lua_State *L, int opt, const gchar **fmt, +static void controloptions (lua_State *L, int opt, const char **fmt, Header *h) { switch (opt) { case ' ': return; /* ignore white spaces */ case '>': h->endian = BIG; return; case '<': h->endian = LITTLE; return; - case '(': h->noassign = TRUE; return; - case ')': h->noassign = FALSE; return; + case '(': h->noassign = true; return; + case ')': h->noassign = false; return; case '!': { - int a = getnum(fmt, MAXALIGN); + int a = getnum(L, fmt, MAXALIGN); if (!isp2(a)) luaL_error(L, "alignment %d is not a power of 2", a); h->align = a; @@ -287,12 +293,12 @@ static void putinteger (lua_State *L, luaL_Buffer *b, int arg, int endian, int size) { lua_Number n = luaL_checknumber(L, arg); /* this one's not system dependent size - it's a long long */ - gint64 value; - gchar buff[MAXINTSIZE]; + int64_t value; + char buff[MAXINTSIZE]; if (n < 0) - value = (guint64)(gint64)n; + value = (uint64_t)(int64_t)n; else - value = (guint64)n; + value = (uint64_t)n; if (endian == LITTLE) { int i; for (i = 0; i < size; i++) { @@ -313,11 +319,11 @@ static void putinteger (lua_State *L, luaL_Buffer *b, int arg, int endian, /* corrects endianness - usually done by other functions themselves, but is * used for float/doubles, since on some platforms they're endian'ed as well */ -static void correctbytes (gchar *b, int size, int endian) { +static void correctbytes (char *b, int size, int endian) { if (endian != native.endian) { int i = 0; while (i < --size) { - gchar temp = b[i]; + char temp = b[i]; b[i++] = b[size]; b[size] = temp; } @@ -368,20 +374,20 @@ WSLUA_CONSTRUCTOR Struct_pack (lua_State *L) { break; } case 'f': { - gfloat f = (gfloat)luaL_checknumber(L, arg++); - correctbytes((gchar *)&f, (int)size, h.endian); - luaL_addlstring(&b, (gchar *)&f, size); + float f = (float)luaL_checknumber(L, arg++); + correctbytes((char *)&f, (int)size, h.endian); + luaL_addlstring(&b, (char *)&f, size); break; } case 'd': { - gdouble d = luaL_checknumber(L, arg++); - correctbytes((gchar *)&d, (int)size, h.endian); - luaL_addlstring(&b, (gchar *)&d, size); + double d = luaL_checknumber(L, arg++); + correctbytes((char *)&d, (int)size, h.endian); + luaL_addlstring(&b, (char *)&d, size); break; } case 'c': case 's': { size_t l; - const gchar *s = luaL_checklstring(L, arg++, &l); + const char *s = luaL_checklstring(L, arg++, &l); if (size == 0) size = l; luaL_argcheck(L, l >= (size_t)size, arg, "string too short"); luaL_addlstring(&b, s, size); @@ -392,7 +398,7 @@ WSLUA_CONSTRUCTOR Struct_pack (lua_State *L) { break; } case '=': { - if (poscnt < (int)(sizeof(posBuf)/sizeof(posBuf[0]))) + if (poscnt < (int)array_length(posBuf)) posBuf[poscnt++] = (int)totalsize + 1; break; } @@ -406,33 +412,54 @@ WSLUA_CONSTRUCTOR Struct_pack (lua_State *L) { WSLUA_RETURN(poscnt + 1); /* The packed binary Lua string, plus any positions due to '=' being used in format. */ } -/* Decodes an integer from a string struct into a Lua number, based on - * given endianness and size. If the integer type is signed, this makes - * the Lua number be +/- correctly as well. - */ -static lua_Number getinteger (const gchar *buff, int endian, - int issigned, int size) { +static Uinttype decodeinteger (const char *buff, int endian, int size) +{ Uinttype l = 0; int i; if (endian == BIG) { for (i = 0; i < size; i++) { l <<= 8; - l |= (Uinttype)(guchar)buff[i]; + l |= (Uinttype)(unsigned char)buff[i]; } } else { for (i = size - 1; i >= 0; i--) { l <<= 8; - l |= (Uinttype)(guchar)buff[i]; + l |= (Uinttype)(unsigned char)buff[i]; + } + } + return l; +} + +/* Decodes an integer from a string struct into a lua_Integer, if it fits + * without truncation, or a lua_Number, based on given endianness and size. + * If the integer type is signed, that is handled correctly as well. + * Note for large values of size there can be a loss of precision. + */ +static void getinteger (lua_State *L, const char *buff, int endian, + int issigned, int size) { + Uinttype l = decodeinteger(buff, endian, size); + if (!issigned) { + if (size < LUA_INTEGER_SIZE) { + /* Fits in a lua_Integer (we need a larger size as lua_Integer + * is signed.) */ + lua_pushinteger(L, (lua_Integer)l); + } else { + /* Does not fit in a lua_Integer */ + lua_pushnumber(L, (lua_Number)l); } } - if (!issigned) - return (lua_Number)l; else { /* signed format */ Uinttype mask = (Uinttype)(~((Uinttype)0)) << (size*8 - 1); if (l & mask) /* negative value? */ - l |= mask; /* signal extension */ - return (lua_Number)(Inttype)l; + l |= mask; /* sign extension */ + if (size <= LUA_INTEGER_SIZE) { + /* Fits in a lua_Integer */ + lua_pushinteger(L, (lua_Integer)(Inttype)l); + } else { + /* Does not fit in a lua_Integer */ + lua_pushnumber(L, (lua_Number)(Inttype)l); + } } } @@ -470,8 +497,7 @@ WSLUA_CONSTRUCTOR Struct_unpack (lua_State *L) { case 'b': case 'B': case 'h': case 'H': case 'l': case 'L': case 'T': case 'i': case 'I': { /* integer types */ int issigned = g_ascii_islower(opt); - lua_Number res = getinteger(data+pos, h.endian, issigned, (int)size); - lua_pushnumber(L, res); + getinteger(L, data+pos, h.endian, issigned, (int)size); break; } case 'e': { @@ -486,16 +512,16 @@ WSLUA_CONSTRUCTOR Struct_unpack (lua_State *L) { break; } case 'f': { - gfloat f; + float f; memcpy(&f, data+pos, size); - correctbytes((gchar *)&f, sizeof(f), h.endian); + correctbytes((char *)&f, sizeof(f), h.endian); lua_pushnumber(L, f); break; } case 'd': { - gdouble d; + double d; memcpy(&d, data+pos, size); - correctbytes((gchar *)&d, sizeof(d), h.endian); + correctbytes((char *)&d, sizeof(d), h.endian); lua_pushnumber(L, d); break; } @@ -503,7 +529,7 @@ WSLUA_CONSTRUCTOR Struct_unpack (lua_State *L) { if (size == 0) { if (!lua_isnumber(L, -1)) luaL_error(L, "format `c0' needs a previous size"); - size = wslua_toguint32(L, -1); + size = wslua_touint32(L, -1); lua_pop(L, 1); luaL_argcheck(L, pos+size <= ld, 2, "data string too short"); } @@ -512,7 +538,7 @@ WSLUA_CONSTRUCTOR Struct_unpack (lua_State *L) { break; } case 's': { - const gchar *e = (const char *)memchr(data+pos, '\0', ld - pos); + const char *e = (const char *)memchr(data+pos, '\0', ld - pos); if (e == NULL) luaL_error(L, "unfinished string in data"); size = (e - (data+pos)) + 1; @@ -537,7 +563,7 @@ WSLUA_CONSTRUCTOR Struct_size (lua_State *L) { /* Returns the length of a binary string that would be consumed/handled by the given format string. */ #define WSLUA_ARG_Struct_size_FORMAT 1 /* The format string */ Header h; - const gchar *fmt = wslua_checkstring_only(L, WSLUA_ARG_Struct_size_FORMAT); + const char *fmt = wslua_checkstring_only(L, WSLUA_ARG_Struct_size_FORMAT); size_t pos = 0; defaultoptions(&h); while (*fmt) { @@ -564,7 +590,7 @@ WSLUA_CONSTRUCTOR Struct_values (lua_State *L) { arguments Struct.pack() expects, not including the format string argument. */ #define WSLUA_ARG_Struct_values_FORMAT 1 /* The format string */ Header h; - const gchar *fmt = wslua_checkstring_only(L, WSLUA_ARG_Struct_values_FORMAT); + const char *fmt = wslua_checkstring_only(L, WSLUA_ARG_Struct_values_FORMAT); size_t vals = 0; defaultoptions(&h); while (*fmt) { @@ -598,19 +624,19 @@ WSLUA_CONSTRUCTOR Struct_tohex (lua_State *L) { #define WSLUA_ARG_Struct_tohex_BYTESTRING 1 /* A Lua string consisting of binary bytes */ #define WSLUA_OPTARG_Struct_tohex_LOWERCASE 2 /* True to use lower-case hex characters (default=false). */ #define WSLUA_OPTARG_Struct_tohex_SEPARATOR 3 /* A string separator to insert between hex bytes (default=nil). */ - const gchar* s = NULL; + const char* s = NULL; size_t len = 0; - gboolean lowercase = FALSE; - const gchar* sep = NULL; + bool lowercase = false; + const char* sep = NULL; /* luaL_checklstring coerces the argument to a string, and that's ok for tohex, just not fromhex. In fact, we should accept/coerce a Int64/UInt64 here too someday. */ s = luaL_checklstring(L, WSLUA_ARG_Struct_tohex_BYTESTRING, &len); - lowercase = wslua_optbool(L,WSLUA_OPTARG_Struct_tohex_LOWERCASE,FALSE); + lowercase = wslua_optbool(L,WSLUA_OPTARG_Struct_tohex_LOWERCASE,false); sep = luaL_optstring(L,WSLUA_OPTARG_Struct_tohex_SEPARATOR,NULL); - wslua_bin2hex(L, s, (guint)len, lowercase, sep); + wslua_bin2hex(L, s, (unsigned)len, lowercase, sep); WSLUA_RETURN(1); /* The Lua hex-ascii string */ } @@ -618,16 +644,16 @@ WSLUA_CONSTRUCTOR Struct_fromhex (lua_State *L) { /* Converts the passed-in hex-ascii string to a binary string. */ #define WSLUA_ARG_Struct_fromhex_HEXBYTES 1 /* A string consisting of hexadecimal bytes like "00 B1 A2" or "1a2b3c4d" */ #define WSLUA_OPTARG_Struct_fromhex_SEPARATOR 2 /* A string separator between hex bytes/words (default none). */ - const gchar* s = NULL; + const char* s = NULL; size_t len = 0; - const gchar* sep = NULL; + const char* sep = NULL; /* luaL_checklstring coerces the argument to a string, and we don't want to do that */ s = wslua_checklstring_only(L, WSLUA_ARG_Struct_fromhex_HEXBYTES, &len); sep = luaL_optstring(L,WSLUA_OPTARG_Struct_fromhex_SEPARATOR,NULL); - wslua_hex2bin(L, s, (guint)len, sep); + wslua_hex2bin(L, s, (unsigned)len, sep); WSLUA_RETURN(1); /* The Lua binary string */ } diff --git a/epan/wslua/wslua_tree.c b/epan/wslua/wslua_tree.c index ff2ac781..2f417a76 100644 --- a/epan/wslua/wslua_tree.c +++ b/epan/wslua/wslua_tree.c @@ -21,9 +21,9 @@ #include <epan/exceptions.h> #include <epan/show_exception.h> -static gint wslua_ett = -1; +static int wslua_ett = -1; -static GPtrArray* outstanding_TreeItem = NULL; +static GPtrArray* outstanding_TreeItem; /* pushing a TreeItem with a NULL item or subtree is completely valid for this function */ @@ -32,7 +32,7 @@ TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item) { ti->tree = tree; ti->item = item; - ti->expired = FALSE; + ti->expired = false; g_ptr_array_add(outstanding_TreeItem, ti); @@ -45,12 +45,12 @@ TreeItem create_TreeItem(proto_tree* tree, proto_item* item) TreeItem tree_item = (TreeItem)g_malloc(sizeof(struct _wslua_treeitem)); tree_item->tree = tree; tree_item->item = item; - tree_item->expired = FALSE; + tree_item->expired = false; return tree_item; } -CLEAR_OUTSTANDING(TreeItem, expired, TRUE) +CLEAR_OUTSTANDING(TreeItem, expired, true) WSLUA_CLASS_DEFINE(TreeItem,FAIL_ON_NULL_OR_EXPIRED("TreeItem")); /* <<lua_class_TreeItem,`TreeItem`>>s represent information in the https://www.wireshark.org/docs/wsug_html_chunked/ChUsePacketDetailsPaneSection.html[packet details] pane of Wireshark, and the packet details view of TShark. @@ -73,11 +73,11 @@ WSLUA_CLASS_DEFINE(TreeItem,FAIL_ON_NULL_OR_EXPIRED("TreeItem")); /* the following is used by TreeItem_add_packet_field() - this can THROW errors */ static proto_item * try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int hfid, - const ftenum_t type, const guint encoding, gint *ret_err) + const ftenum_t type, const unsigned encoding, int *ret_err) { - gint err = 0; + int err = 0; proto_item *volatile item = NULL; - gint endoff = 0; + int endoff = 0; switch(type) { /* these all generate ByteArrays */ @@ -119,11 +119,11 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_INT24: case FT_INT32: { - gint32 ret; + int32_t ret; item = proto_tree_add_item_ret_int(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); - lua_pushnumber(L, (lua_Number)ret); + lua_pushinteger(L, (lua_Integer)ret); lua_pushinteger(L, tvbr->offset + tvbr->len); } break; @@ -133,7 +133,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_INT56: case FT_INT64: { - gint64 ret; + int64_t ret; item = proto_tree_add_item_ret_int64(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); @@ -148,11 +148,11 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_UINT24: case FT_UINT32: { - guint32 ret; + uint32_t ret; item = proto_tree_add_item_ret_uint(tree_item-> tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); - lua_pushnumber(L, (lua_Number)ret); + lua_pushinteger(L, (lua_Integer)ret); lua_pushinteger(L, tvbr->offset + tvbr->len); } break; @@ -162,7 +162,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_UINT56: case FT_UINT64: { - guint64 ret; + uint64_t ret; item = proto_tree_add_item_ret_uint64(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); @@ -173,7 +173,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_BOOLEAN: { - gboolean ret; + bool ret; item = proto_tree_add_item_ret_boolean(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); @@ -184,8 +184,8 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_STRING: { - const guint8 *ret; - gint len; + const uint8_t *ret; + int len; item = proto_tree_add_item_ret_string_and_length(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, NULL, &ret, &len); @@ -197,8 +197,8 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_STRINGZ: { - const guint8 *ret; - gint len; + const uint8_t *ret; + int len; item = proto_tree_add_item_ret_string_and_length(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, -1, encoding, NULL, &ret, &len); @@ -210,7 +210,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_FLOAT: { - gfloat ret; + float ret; item = proto_tree_add_item_ret_float(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); @@ -221,7 +221,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_DOUBLE: { - gdouble ret; + double ret; item = proto_tree_add_item_ret_double(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, &ret); @@ -259,7 +259,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int case FT_ETHER: { Address addr = g_new(address, 1); - guint8 bytes[FT_ETHER_LEN]; + uint8_t bytes[FT_ETHER_LEN]; item = proto_tree_add_item_ret_ether(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, @@ -351,10 +351,10 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) { volatile int ett; ftenum_t type; TreeItem tree_item = shiftTreeItem(L,1); - guint encoding; + unsigned encoding; proto_item* item = NULL; volatile int nargs; - volatile gint err = 0; + volatile int err = 0; const char *volatile error = NULL; if (!tree_item) { @@ -383,7 +383,7 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) { tvbr->len = 0; } - encoding = wslua_checkguint(L,1); + encoding = wslua_checkuint(L,1); lua_remove(L,1); /* get the number of additional args before we add more to the stack */ @@ -402,7 +402,7 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) { break; default: - if (tvb_find_guint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) { + if (tvb_find_uint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) { luaL_error(L,"out of bounds"); return 0; } @@ -412,7 +412,7 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) { } TRY { - gint errx = 0; + int errx = 0; item = try_add_packet_field(L, tree_item, tvbr, hfid, type, encoding, &errx); err = errx; } CATCH_ALL { @@ -428,7 +428,7 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) { } while(nargs) { - const gchar* s; + const char* s; s = lua_tostring(L,1); if (s) proto_item_append_text(item, " %s", s); lua_remove(L,1); @@ -443,7 +443,7 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) { WSLUA_RETURN(3); /* The new child <<lua_class_TreeItem,`TreeItem`>>, the field's extracted value or nil, and offset or nil. */ } -static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { +static int TreeItem_add_item_any(lua_State *L, bool little_endian) { TvbRange tvbr; Proto proto; ProtoField field; @@ -489,7 +489,7 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { /* hfid is > 0 when the first arg was a ProtoField or Proto */ if (type == FT_STRINGZ) { - if (tvb_find_guint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) { + if (tvb_find_uint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) { luaL_error(L,"out of bounds"); return 0; } @@ -502,13 +502,22 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { switch(type) { case FT_PROTOCOL: item = proto_tree_add_item(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,ENC_NA); - lua_pushnumber(L,0); + lua_pushinteger(L,0); lua_insert(L,1); break; case FT_BOOLEAN: { - /* this needs to use checkinteger so that it can accept a Lua boolean and coerce it to an int */ - guint32 val = (guint32) (wslua_tointeger(L,1)); + uint64_t val; + switch(lua_type(L, 1)) { + + case LUA_TUSERDATA: + val = checkUInt64(L, 1); + break; + + default: + /* this needs to use checkinteger so that it can accept a Lua boolean and coerce it to an int */ + val = (uint64_t) (wslua_tointeger(L,1)); + } item = proto_tree_add_boolean(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,val); } break; @@ -518,13 +527,13 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { case FT_UINT24: case FT_UINT32: case FT_FRAMENUM: - item = proto_tree_add_uint(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,wslua_checkguint32(L,1)); + item = proto_tree_add_uint(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,wslua_checkuint32(L,1)); break; case FT_INT8: case FT_INT16: case FT_INT24: case FT_INT32: - item = proto_tree_add_int(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,wslua_checkgint32(L,1)); + item = proto_tree_add_int(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,wslua_checkint32(L,1)); break; case FT_FLOAT: item = proto_tree_add_float(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(float)luaL_checknumber(L,1)); @@ -541,7 +550,7 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { item = proto_tree_add_string(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,luaL_checkstring(L,1)); break; case FT_BYTES: - item = proto_tree_add_bytes(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len, (const guint8*) luaL_checkstring(L,1)); + item = proto_tree_add_bytes(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len, (const uint8_t*) luaL_checkstring(L,1)); break; case FT_UINT64: item = proto_tree_add_uint64(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,checkUInt64(L,1)); @@ -552,7 +561,7 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { case FT_IPv4: { Address addr = checkAddress(L,1); - guint32 addr_value; + uint32_t addr_value; if (addr->type != AT_IPv4) { luaL_error(L, "Expected IPv4 address for FT_IPv4 field"); @@ -587,7 +596,7 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { return 0; } - item = proto_tree_add_ether(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, (const guint8 *)addr->data); + item = proto_tree_add_ether(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, (const uint8_t *)addr->data); } break; case FT_UINT_BYTES: @@ -616,7 +625,7 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { if ( lua_gettop(L) ) { /* if there was a value, it was removed earlier, so what's left is the display string to set */ - const gchar* s = lua_tostring(L,1); + const char* s = lua_tostring(L,1); if (s) proto_item_set_text(item,"%s",s); lua_remove(L,1); } @@ -624,7 +633,7 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { } else { /* no ProtoField or Proto was given */ if (lua_gettop(L)) { - const gchar* s = lua_tostring(L,1); + const char* s = lua_tostring(L,1); const int hf = get_hf_wslua_text(); if (hf > -1) { /* use proto_tree_add_none_format() instead? */ @@ -641,7 +650,7 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) { while(lua_gettop(L)) { /* keep appending more text */ - const gchar* s = lua_tostring(L,1); + const char* s = lua_tostring(L,1); if (s) proto_item_append_text(item, " %s", s); lua_remove(L,1); } @@ -664,6 +673,7 @@ WSLUA_METHOD TreeItem_add(lua_State *L) { which is invalid for this function). If the first argument is a non-<<lua_class_ProtoField,`ProtoField`>> and a non-<<lua_class_Proto,`Proto`>> then this argument can be either a <<lua_class_TvbRange,`TvbRange`>> or a label, and the value is not in use. + [discrete] ====== Example [source,lua] @@ -716,7 +726,7 @@ WSLUA_METHOD TreeItem_add(lua_State *L) { #define WSLUA_OPTARG_TreeItem_add_TVBRANGE 3 /* The <<lua_class_TvbRange,`TvbRange`>> of bytes in the packet this tree item covers/represents. */ #define WSLUA_OPTARG_TreeItem_add_VALUE 4 /* The field's value, instead of the ProtoField/Proto one. */ #define WSLUA_OPTARG_TreeItem_add_LABEL 5 /* One or more strings to use for the tree item label, instead of the ProtoField/Proto one. */ - WSLUA_RETURN(TreeItem_add_item_any(L,FALSE)); /* The new child TreeItem. */ + WSLUA_RETURN(TreeItem_add_item_any(L,false)); /* The new child TreeItem. */ } WSLUA_METHOD TreeItem_add_le(lua_State *L) { @@ -735,19 +745,17 @@ WSLUA_METHOD TreeItem_add_le(lua_State *L) { #define WSLUA_OPTARG_TreeItem_add_le_TVBRANGE 3 /* The TvbRange of bytes in the packet this tree item covers/represents. */ #define WSLUA_OPTARG_TreeItem_add_le_VALUE 4 /* The field's value, instead of the ProtoField/Proto one. */ #define WSLUA_OPTARG_TreeItem_add_le_LABEL 5 /* One or more strings to use for the tree item label, instead of the ProtoField/Proto one. */ - WSLUA_RETURN(TreeItem_add_item_any(L,TRUE)); /* The new child TreeItem. */ + WSLUA_RETURN(TreeItem_add_item_any(L,true)); /* The new child TreeItem. */ } /* WSLUA_ATTRIBUTE TreeItem_text RW Set/get the <<lua_class_TreeItem,`TreeItem`>>'s display string (string). For the getter, if the TreeItem has no display string, then nil is returned. - - @since 1.99.3 */ static int TreeItem_get_text(lua_State* L) { TreeItem ti = checkTreeItem(L,1); - gchar label_str[ITEM_LABEL_LENGTH+1]; - gchar *label_ptr; + char label_str[ITEM_LABEL_LENGTH+1]; + char *label_ptr; if (ti->item) { field_info *fi = PITEM_FINFO(ti->item); @@ -778,7 +786,7 @@ WSLUA_METHOD TreeItem_set_text(lua_State *L) { */ #define WSLUA_ARG_TreeItem_set_text_TEXT 2 /* The text to be used. */ TreeItem ti = checkTreeItem(L,1); - const gchar* s = luaL_checkstring(L,WSLUA_ARG_TreeItem_set_text_TEXT); + const char* s = luaL_checkstring(L,WSLUA_ARG_TreeItem_set_text_TEXT); proto_item_set_text(ti->item,"%s",s); @@ -795,7 +803,7 @@ WSLUA_METHOD TreeItem_append_text(lua_State *L) { */ #define WSLUA_ARG_TreeItem_append_text_TEXT 2 /* The text to be appended. */ TreeItem ti = checkTreeItem(L,1); - const gchar* s = luaL_checkstring(L,WSLUA_ARG_TreeItem_append_text_TEXT); + const char* s = luaL_checkstring(L,WSLUA_ARG_TreeItem_append_text_TEXT); proto_item_append_text(ti->item,"%s",s); @@ -812,7 +820,7 @@ WSLUA_METHOD TreeItem_prepend_text(lua_State *L) { */ #define WSLUA_ARG_TreeItem_prepend_text_TEXT 2 /* The text to be prepended. */ TreeItem ti = checkTreeItem(L,1); - const gchar* s = luaL_checkstring(L,WSLUA_ARG_TreeItem_prepend_text_TEXT); + const char* s = luaL_checkstring(L,WSLUA_ARG_TreeItem_prepend_text_TEXT); proto_item_prepend_text(ti->item,"%s",s); @@ -832,18 +840,36 @@ WSLUA_METHOD TreeItem_add_expert_info(lua_State *L) { be used in new Lua code. It may be removed in the future. You should only use `TreeItem.add_proto_expert_info()`. */ -#define WSLUA_OPTARG_TreeItem_add_expert_info_GROUP 2 /* One of `PI_CHECKSUM`, `PI_SEQUENCE`, - `PI_RESPONSE_CODE`, `PI_REQUEST_CODE`, - `PI_UNDECODED`, `PI_REASSEMBLE`, - `PI_MALFORMED` or `PI_DEBUG`. */ -#define WSLUA_OPTARG_TreeItem_add_expert_info_SEVERITY 3 /* One of `PI_CHAT`, `PI_NOTE`, - `PI_WARN`, or `PI_ERROR`. */ +#define WSLUA_OPTARG_TreeItem_add_expert_info_GROUP 2 /* One of: + `PI_CHECKSUM`, + `PI_SEQUENCE`, + `PI_RESPONSE_CODE`, + `PI_REQUEST_CODE`, + `PI_UNDECODED`, + `PI_REASSEMBLE`, + `PI_MALFORMED`, + `PI_DEBUG`, + `PI_PROTOCOL`, + `PI_SECURITY`, + `PI_COMMENTS_GROUP`, + `PI_DECRYPTION`, + `PI_ASSUMPTION`, + `PI_DEPRECATED`, + `PI_RECEIVE`, + `PI_INTERFACE`, + or `PI_DISSECTOR_BUG`. */ +#define WSLUA_OPTARG_TreeItem_add_expert_info_SEVERITY 3 /* One of: + `PI_COMMENT`, + `PI_CHAT`, + `PI_NOTE`, + `PI_WARN`, + or `PI_ERROR`. */ #define WSLUA_OPTARG_TreeItem_add_expert_info_TEXT 4 /* The text for the expert info display. */ TreeItem ti = checkTreeItem(L,1); int group = (int)luaL_optinteger(L,WSLUA_OPTARG_TreeItem_add_expert_info_GROUP,PI_DEBUG); int severity = (int)luaL_optinteger(L,WSLUA_OPTARG_TreeItem_add_expert_info_SEVERITY,PI_CHAT); expert_field* ei_info = wslua_get_expert_field(group, severity); - const gchar* str; + const char* str; if (lua_gettop(L) >= WSLUA_OPTARG_TreeItem_add_expert_info_TEXT) { str = wslua_checkstring_only(L, WSLUA_OPTARG_TreeItem_add_expert_info_TEXT); @@ -859,17 +885,14 @@ WSLUA_METHOD TreeItem_add_expert_info(lua_State *L) { } WSLUA_METHOD TreeItem_add_proto_expert_info(lua_State *L) { - /* Sets the expert flags of the tree item and adds expert info to the packet. - - @since 1.11.3 - */ + /* Sets the expert flags of the tree item and adds expert info to the packet. */ #define WSLUA_ARG_TreeItem_add_proto_expert_info_EXPERT 2 /* The <<lua_class_ProtoExpert,`ProtoExpert`>> object to add to the tree. */ #define WSLUA_OPTARG_TreeItem_add_proto_expert_info_TEXT 3 /* Text for the expert info display (default is to use the registered text). */ TreeItem ti = checkTreeItem(L,1); ProtoExpert expert = checkProtoExpert(L,WSLUA_ARG_TreeItem_add_proto_expert_info_EXPERT); - const gchar* str; + const char* str; if (expert->ids.ei == EI_INIT_EI || expert->ids.hf == EI_INIT_HF) { luaL_error(L, "ProtoExpert is not registered"); @@ -891,10 +914,7 @@ WSLUA_METHOD TreeItem_add_proto_expert_info(lua_State *L) { WSLUA_METHOD TreeItem_add_tvb_expert_info(lua_State *L) { /* Sets the expert flags of the tree item and adds expert info to the packet - associated with the <<lua_class_Tvb,`Tvb`>> or <<lua_class_TvbRange,`TvbRange`>> bytes in the packet. - - @since 1.11.3 - */ + associated with the <<lua_class_Tvb,`Tvb`>> or <<lua_class_TvbRange,`TvbRange`>> bytes in the packet. */ #define WSLUA_ARG_TreeItem_add_tvb_expert_info_EXPERT 2 /* The <<lua_class_ProtoExpert,`ProtoExpert`>> object to add to the tree. */ #define WSLUA_ARG_TreeItem_add_tvb_expert_info_TVB 3 /* The <<lua_class_Tvb,`Tvb`>> or <<lua_class_TvbRange,`TvbRange`>> object bytes to associate the expert info with. */ @@ -904,7 +924,7 @@ WSLUA_METHOD TreeItem_add_tvb_expert_info(lua_State *L) { TreeItem ti = checkTreeItem(L,1); ProtoExpert expert = checkProtoExpert(L,WSLUA_ARG_TreeItem_add_proto_expert_info_EXPERT); TvbRange tvbr; - const gchar* str; + const char* str; if (expert->ids.ei == EI_INIT_EI || expert->ids.hf == EI_INIT_HF) { luaL_error(L, "ProtoExpert is not registered"); @@ -941,10 +961,7 @@ WSLUA_METHOD TreeItem_add_tvb_expert_info(lua_State *L) { } -/* WSLUA_ATTRIBUTE TreeItem_visible RO Get the <<lua_class_TreeItem,`TreeItem`>>'s subtree visibility status (boolean). - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE TreeItem_visible RO Get the <<lua_class_TreeItem,`TreeItem`>>'s subtree visibility status (boolean). */ static int TreeItem_get_visible(lua_State* L) { TreeItem ti = checkTreeItem(L,1); @@ -952,17 +969,14 @@ static int TreeItem_get_visible(lua_State* L) { lua_pushboolean(L, PTREE_DATA(ti->tree)->visible); } else { - lua_pushboolean(L, FALSE); + lua_pushboolean(L, false); } return 1; } -/* WSLUA_ATTRIBUTE TreeItem_generated RW Set/get the <<lua_class_TreeItem,`TreeItem`>>'s generated state (boolean). - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE TreeItem_generated RW Set/get the <<lua_class_TreeItem,`TreeItem`>>'s generated state (boolean). */ static int TreeItem_get_generated(lua_State* L) { TreeItem ti = checkTreeItem(L,1); @@ -981,7 +995,7 @@ WSLUA_METHOD TreeItem_set_generated(lua_State *L) { #define WSLUA_OPTARG_TreeItem_set_generated_BOOL 2 /* A Lua boolean, which if `true` sets the <<lua_class_TreeItem,`TreeItem`>> generated flag, else clears it (default=true) */ TreeItem ti = checkTreeItem(L,1); - gboolean set = wslua_optbool(L, WSLUA_OPTARG_TreeItem_set_generated_BOOL, TRUE); + bool set = wslua_optbool(L, WSLUA_OPTARG_TreeItem_set_generated_BOOL, true); if (set) { proto_item_set_generated(ti->item); @@ -996,10 +1010,7 @@ WSLUA_METHOD TreeItem_set_generated(lua_State *L) { WSLUA_RETURN(1); /* The same TreeItem. */ } -/* WSLUA_ATTRIBUTE TreeItem_hidden RW Set/get <<lua_class_TreeItem,`TreeItem`>>'s hidden state (boolean). - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE TreeItem_hidden RW Set/get <<lua_class_TreeItem,`TreeItem`>>'s hidden state (boolean). */ static int TreeItem_get_hidden(lua_State* L) { TreeItem ti = checkTreeItem(L,1); @@ -1020,7 +1031,7 @@ WSLUA_METHOD TreeItem_set_hidden(lua_State *L) { #define WSLUA_OPTARG_TreeItem_set_hidden_BOOL 2 /* A Lua boolean, which if `true` sets the <<lua_class_TreeItem,`TreeItem`>> hidden flag, else clears it. Default is `true`. */ TreeItem ti = checkTreeItem(L,1); - gboolean set = wslua_optbool(L, WSLUA_OPTARG_TreeItem_set_hidden_BOOL, TRUE); + bool set = wslua_optbool(L, WSLUA_OPTARG_TreeItem_set_hidden_BOOL, true); if (set) { proto_item_set_hidden(ti->item); @@ -1034,10 +1045,7 @@ WSLUA_METHOD TreeItem_set_hidden(lua_State *L) { WSLUA_RETURN(1); /* The same TreeItem. */ } -/* WSLUA_ATTRIBUTE TreeItem_len RW Set/get <<lua_class_TreeItem,`TreeItem`>>'s length inside tvb, after it has already been created. - - @since 1.99.8 - */ +/* WSLUA_ATTRIBUTE TreeItem_len RW Set/get <<lua_class_TreeItem,`TreeItem`>>'s length inside tvb, after it has already been created. */ static int TreeItem_get_len(lua_State* L) { TreeItem ti = checkTreeItem(L,1); int len = 0; @@ -1057,7 +1065,7 @@ WSLUA_METHOD TreeItem_set_len(lua_State *L) { */ #define WSLUA_ARG_TreeItem_set_len_LEN 2 /* The length to be used. */ TreeItem ti = checkTreeItem(L,1); - gint len = (int)luaL_checkinteger(L,WSLUA_ARG_TreeItem_set_len_LEN); + int len = (int)luaL_checkinteger(L,WSLUA_ARG_TreeItem_set_len_LEN); proto_item_set_len(ti->item, len); @@ -1075,13 +1083,11 @@ WSLUA_METHOD TreeItem_referenced(lua_State *L) { usually run faster since Wireshark will not do extra dissection work when it doesn't need the field. You can use this in conjunction with the TreeItem.visible attribute. This function will always return - TRUE when the TreeItem is visible. When it is not visible and the field is not referenced, you can + true when the TreeItem is visible. When it is not visible and the field is not referenced, you can speed up the dissection by not dissecting the field as it is not needed for display or filtering. This function takes one parameter that can be a <<lua_class_ProtoField,`ProtoField`>> or <<lua_class_Dissector,`Dissector`>>. The <<lua_class_Dissector,`Dissector`>> form is useful when you need to decide whether to call a sub-dissector. - - @since 2.4.0 */ #define WSLUA_ARG_TreeItem_referenced_PROTOFIELD 2 /* The <<lua_class_ProtoField,`ProtoField`>> or <<lua_class_Dissector,`Dissector`>> to check if referenced. */ TreeItem ti = checkTreeItem(L, 1); @@ -1099,10 +1105,7 @@ WSLUA_METHOD TreeItem_referenced(lua_State *L) { } WSLUA_METAMETHOD TreeItem__tostring(lua_State* L) { - /* Returns string debug information about the <<lua_class_TreeItem,`TreeItem`>>. - - @since 1.99.8 - */ + /* Returns string debug information about the <<lua_class_TreeItem,`TreeItem`>>. */ TreeItem ti = toTreeItem(L,1); if (ti) { @@ -1125,7 +1128,7 @@ static int TreeItem__gc(lua_State* L) { TreeItem ti = toTreeItem(L,1); if (!ti) return 0; if (!ti->expired) - ti->expired = TRUE; + ti->expired = true; else g_free(ti); return 0; @@ -1163,9 +1166,12 @@ WSLUA_META TreeItem_meta[] = { }; int TreeItem_register(lua_State *L) { - gint* etts[] = { &wslua_ett }; + int* etts[] = { &wslua_ett }; wslua_ett = -1; /* Reset to support reload Lua plugins */ WSLUA_REGISTER_CLASS_WITH_ATTRS(TreeItem); + if (outstanding_TreeItem != NULL) { + g_ptr_array_unref(outstanding_TreeItem); + } outstanding_TreeItem = g_ptr_array_new(); proto_register_subtree_array(etts,1); return 0; diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c index 031023d0..9fe8fbc1 100644 --- a/epan/wslua/wslua_tvb.c +++ b/epan/wslua/wslua_tvb.c @@ -62,8 +62,8 @@ WSLUA_CLASS_DEFINE(Tvb,FAIL_ON_NULL_OR_EXPIRED("Tvb")); ==== */ -static GPtrArray* outstanding_Tvb = NULL; -static GPtrArray* outstanding_TvbRange = NULL; +static GPtrArray* outstanding_Tvb; +static GPtrArray* outstanding_TvbRange; /* this is used to push Tvbs that were created brand new by wslua code */ int push_wsluaTvb(lua_State* L, Tvb t) { @@ -79,7 +79,7 @@ static void free_Tvb(Tvb tvb) { if (!tvb) return; if (!tvb->expired) { - tvb->expired = TRUE; + tvb->expired = true; } else { if (tvb->need_free) tvb_free(tvb->ws_tvb); @@ -98,8 +98,8 @@ void clear_outstanding_Tvb(void) { Tvb* push_Tvb(lua_State* L, tvbuff_t* ws_tvb) { Tvb tvb = (Tvb)g_malloc(sizeof(struct _wslua_tvb)); tvb->ws_tvb = ws_tvb; - tvb->expired = FALSE; - tvb->need_free = FALSE; + tvb->expired = false; + tvb->need_free = false; g_ptr_array_add(outstanding_Tvb,tvb); return pushTvb(L,tvb); } @@ -135,7 +135,7 @@ WSLUA_METHOD Tvb_reported_len(lua_State* L) { /* Obtain the reported length (length on the network) of a <<lua_class_Tvb,`Tvb`>>. */ Tvb tvb = checkTvb(L,1); - lua_pushnumber(L,tvb_reported_length(tvb->ws_tvb)); + lua_pushinteger(L,tvb_reported_length(tvb->ws_tvb)); WSLUA_RETURN(1); /* The reported length of the <<lua_class_Tvb,`Tvb`>>. */ } @@ -143,7 +143,7 @@ WSLUA_METHOD Tvb_captured_len(lua_State* L) { /* Obtain the captured length (amount saved in the capture process) of a <<lua_class_Tvb,`Tvb`>>. */ Tvb tvb = checkTvb(L,1); - lua_pushnumber(L,tvb_captured_length(tvb->ws_tvb)); + lua_pushinteger(L,tvb_captured_length(tvb->ws_tvb)); WSLUA_RETURN(1); /* The captured length of the <<lua_class_Tvb,`Tvb`>>. */ } @@ -152,26 +152,23 @@ WSLUA_METHOD Tvb_len(lua_State* L) { Same as captured_len; kept only for backwards compatibility */ Tvb tvb = checkTvb(L,1); - lua_pushnumber(L,tvb_captured_length(tvb->ws_tvb)); + lua_pushinteger(L,tvb_captured_length(tvb->ws_tvb)); WSLUA_RETURN(1); /* The captured length of the <<lua_class_Tvb,`Tvb`>>. */ } WSLUA_METHOD Tvb_reported_length_remaining(lua_State* L) { /* Obtain the reported (not captured) length of packet data to end of a <<lua_class_Tvb,`Tvb`>> or 0 if the offset is beyond the end of the <<lua_class_Tvb,`Tvb`>>. */ -#define WSLUA_OPTARG_Tvb_reported_length_remaining_OFFSET 2 /* offset */ +#define WSLUA_OPTARG_Tvb_reported_length_remaining_OFFSET 2 /* The offset (in octets) from the beginning of the <<lua_class_Tvb,`Tvb`>>. Defaults to 0. */ Tvb tvb = checkTvb(L,1); int offset = (int) luaL_optinteger(L, WSLUA_OPTARG_Tvb_reported_length_remaining_OFFSET, 0); - lua_pushnumber(L,tvb_reported_length_remaining(tvb->ws_tvb, offset)); - WSLUA_RETURN(1); /* The captured length of the <<lua_class_Tvb,`Tvb`>>. */ + lua_pushinteger(L,tvb_reported_length_remaining(tvb->ws_tvb, offset)); + WSLUA_RETURN(1); /* The remaining reported length of the <<lua_class_Tvb,`Tvb`>>. */ } WSLUA_METHOD Tvb_bytes(lua_State* L) { - /* Obtain a <<lua_class_ByteArray,`ByteArray`>> from a <<lua_class_Tvb,`Tvb`>>. - - @since 1.99.8 - */ + /* Obtain a <<lua_class_ByteArray,`ByteArray`>> from a <<lua_class_Tvb,`Tvb`>>. */ #define WSLUA_OPTARG_Tvb_bytes_OFFSET 2 /* The offset (in octets) from the beginning of the <<lua_class_Tvb,`Tvb`>>. Defaults to 0. */ #define WSLUA_OPTARG_Tvb_bytes_LENGTH 3 /* The length (in octets) of the range. Defaults to until the end of the <<lua_class_Tvb,`Tvb`>>. */ Tvb tvb = checkTvb(L,1); @@ -194,7 +191,7 @@ WSLUA_METHOD Tvb_bytes(lua_State* L) { luaL_error(L,"out of bounds"); return 0; } - } else if ( (guint)(len + offset) > tvb_captured_length(tvb->ws_tvb)) { + } else if ( (unsigned)(len + offset) > tvb_captured_length(tvb->ws_tvb)) { luaL_error(L,"Range is out of bounds"); return 0; } @@ -210,7 +207,7 @@ WSLUA_METHOD Tvb_offset(lua_State* L) { /* Returns the raw offset (from the beginning of the source <<lua_class_Tvb,`Tvb`>>) of a sub <<lua_class_Tvb,`Tvb`>>. */ Tvb tvb = checkTvb(L,1); - lua_pushnumber(L,tvb_raw_offset(tvb->ws_tvb)); + lua_pushinteger(L,tvb_raw_offset(tvb->ws_tvb)); WSLUA_RETURN(1); /* The raw offset of the <<lua_class_Tvb,`Tvb`>>. */ } @@ -240,10 +237,7 @@ WSLUA_METHOD Tvb_range(lua_State* L) { } WSLUA_METHOD Tvb_raw(lua_State* L) { - /* Obtain a Lua string of the binary bytes in a <<lua_class_Tvb,`Tvb`>>. - - @since 1.11.3 - */ + /* Obtain a Lua string of the binary bytes in a <<lua_class_Tvb,`Tvb`>>. */ #define WSLUA_OPTARG_Tvb_raw_OFFSET 2 /* The position of the first byte. Default is 0, or the first byte. */ #define WSLUA_OPTARG_Tvb_raw_LENGTH 3 /* The length of the segment to get. Default is -1, or the remaining bytes in the <<lua_class_Tvb,`Tvb`>>. */ Tvb tvb = checkTvb(L,1); @@ -256,7 +250,7 @@ WSLUA_METHOD Tvb_raw(lua_State* L) { return 0; } - if ((guint)offset > tvb_captured_length(tvb->ws_tvb)) { + if ((unsigned)offset > tvb_captured_length(tvb->ws_tvb)) { WSLUA_OPTARG_ERROR(Tvb_raw,OFFSET,"offset beyond end of Tvb"); return 0; } @@ -265,11 +259,11 @@ WSLUA_METHOD Tvb_raw(lua_State* L) { len = tvb_captured_length_remaining(tvb->ws_tvb,offset); if (len < 0) { luaL_error(L,"out of bounds"); - return FALSE; + return false; } - } else if ( (guint)(len + offset) > tvb_captured_length(tvb->ws_tvb)) { + } else if ( (unsigned)(len + offset) > tvb_captured_length(tvb->ws_tvb)) { luaL_error(L,"Range is out of bounds"); - return FALSE; + return false; } lua_pushlstring(L, tvb_get_ptr(tvb->ws_tvb, offset, len), len); @@ -278,10 +272,7 @@ WSLUA_METHOD Tvb_raw(lua_State* L) { } WSLUA_METAMETHOD Tvb__eq(lua_State* L) { - /* Checks whether contents of two <<lua_class_Tvb,`Tvb`>>s are equal. - - @since 1.99.8 - */ + /* Checks whether contents of two <<lua_class_Tvb,`Tvb`>>s are equal. */ Tvb tvb_l = checkTvb(L,1); Tvb tvb_r = checkTvb(L,2); @@ -291,8 +282,8 @@ WSLUA_METAMETHOD Tvb__eq(lua_State* L) { /* it is not an error if their ds_tvb are different... they're just not equal */ if (len_l == len_r) { - const gchar* lp = tvb_get_ptr(tvb_l->ws_tvb, 0, len_l); - const gchar* rp = tvb_get_ptr(tvb_r->ws_tvb, 0, len_r); + const char* lp = tvb_get_ptr(tvb_l->ws_tvb, 0, len_l); + const char* rp = tvb_get_ptr(tvb_r->ws_tvb, 0, len_r); int i = 0; for (; i < len_l; ++i) { @@ -330,6 +321,9 @@ WSLUA_META Tvb_meta[] = { int Tvb_register(lua_State* L) { WSLUA_REGISTER_CLASS(Tvb); + if (outstanding_Tvb != NULL) { + g_ptr_array_unref(outstanding_Tvb); + } outstanding_Tvb = g_ptr_array_new(); return 0; } @@ -350,7 +344,7 @@ static void free_TvbRange(TvbRange tvbr) { if (!(tvbr && tvbr->tvb)) return; if (!tvbr->tvb->expired) { - tvbr->tvb->expired = TRUE; + tvbr->tvb->expired = true; } else { free_Tvb(tvbr->tvb); g_free(tvbr); @@ -365,39 +359,39 @@ void clear_outstanding_TvbRange(void) { } -gboolean push_TvbRange(lua_State* L, tvbuff_t* ws_tvb, int offset, int len) { +bool push_TvbRange(lua_State* L, tvbuff_t* ws_tvb, int offset, int len) { TvbRange tvbr; if (!ws_tvb) { luaL_error(L,"expired tvb"); - return FALSE; + return false; } if (len == -1) { len = tvb_captured_length_remaining(ws_tvb,offset); if (len < 0) { luaL_error(L,"out of bounds"); - return FALSE; + return false; } } else if (len < -1) { luaL_error(L, "negative length in tvb range"); - return FALSE; - } else if ( (guint)(len + offset) > tvb_captured_length(ws_tvb)) { + return false; + } else if ( (unsigned)(len + offset) > tvb_captured_length(ws_tvb)) { luaL_error(L,"Range is out of bounds"); - return FALSE; + return false; } tvbr = (TvbRange)g_malloc(sizeof(struct _wslua_tvbrange)); tvbr->tvb = (Tvb)g_malloc(sizeof(struct _wslua_tvb)); tvbr->tvb->ws_tvb = ws_tvb; - tvbr->tvb->expired = FALSE; - tvbr->tvb->need_free = FALSE; + tvbr->tvb->expired = false; + tvbr->tvb->need_free = false; tvbr->offset = offset; tvbr->len = len; PUSH_TVBRANGE(L,tvbr); - return TRUE; + return true; } @@ -415,8 +409,8 @@ WSLUA_METHOD TvbRange_tvb(lua_State *L) { if (tvb_offset_exists(tvbr->tvb->ws_tvb, tvbr->offset + tvbr->len -1 )) { tvb = (Tvb)g_malloc(sizeof(struct _wslua_tvb)); - tvb->expired = FALSE; - tvb->need_free = FALSE; + tvb->expired = false; + tvb->need_free = false; tvb->ws_tvb = tvb_new_subset_length(tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len); return push_wsluaTvb(L, tvb); } else { @@ -441,16 +435,16 @@ WSLUA_METHOD TvbRange_uint(lua_State* L) { switch (tvbr->len) { case 1: - lua_pushnumber(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_uint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushnumber(L,tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushnumber(L,tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushnumber(L,tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The unsigned integer value. */ default: luaL_error(L,"TvbRange:uint() does not handle %d byte integers",tvbr->len); @@ -474,16 +468,16 @@ WSLUA_METHOD TvbRange_le_uint(lua_State* L) { switch (tvbr->len) { case 1: /* XXX unsigned anyway */ - lua_pushnumber(L,(lua_Number)(guint)tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,(lua_Integer)(unsigned)tvb_get_uint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushnumber(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushnumber(L,tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushnumber(L,tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The unsigned integer value */ default: luaL_error(L,"TvbRange:le_uint() does not handle %d byte integers",tvbr->len); @@ -506,7 +500,7 @@ WSLUA_METHOD TvbRange_uint64(lua_State* L) { switch (tvbr->len) { case 1: - pushUInt64(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); + pushUInt64(L,tvb_get_uint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: pushUInt64(L,tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset)); @@ -550,7 +544,7 @@ WSLUA_METHOD TvbRange_le_uint64(lua_State* L) { switch (tvbr->len) { case 1: - pushUInt64(L,tvb_get_guint8(tvbr->tvb->ws_tvb,tvbr->offset)); + pushUInt64(L,tvb_get_uint8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: pushUInt64(L,tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset)); @@ -594,16 +588,16 @@ WSLUA_METHOD TvbRange_int(lua_State* L) { switch (tvbr->len) { case 1: - lua_pushnumber(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_int8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushnumber(L,tvb_get_ntohis(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohis(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushnumber(L,tvb_get_ntohi24(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohi24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushnumber(L,tvb_get_ntohil(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_ntohil(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The signed integer value. */ /* * XXX: @@ -633,16 +627,16 @@ WSLUA_METHOD TvbRange_le_int(lua_State* L) { switch (tvbr->len) { case 1: - lua_pushnumber(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_int8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: - lua_pushnumber(L,tvb_get_letohis(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohis(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 3: - lua_pushnumber(L,tvb_get_letohi24(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohi24(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 4: - lua_pushnumber(L,tvb_get_letohil(tvbr->tvb->ws_tvb,tvbr->offset)); + lua_pushinteger(L,tvb_get_letohil(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The signed integer value. */ default: luaL_error(L,"TvbRange:le_int() does not handle %d byte integers",tvbr->len); @@ -665,7 +659,7 @@ WSLUA_METHOD TvbRange_int64(lua_State* L) { switch (tvbr->len) { case 1: - pushInt64(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); + pushInt64(L,tvb_get_int8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: pushInt64(L,tvb_get_ntohis(tvbr->tvb->ws_tvb,tvbr->offset)); @@ -709,7 +703,7 @@ WSLUA_METHOD TvbRange_le_int64(lua_State* L) { switch (tvbr->len) { case 1: - pushInt64(L,tvb_get_gint8(tvbr->tvb->ws_tvb,tvbr->offset)); + pushInt64(L,tvb_get_int8(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; case 2: pushInt64(L,tvb_get_letohis(tvbr->tvb->ws_tvb,tvbr->offset)); @@ -803,7 +797,7 @@ WSLUA_METHOD TvbRange_ipv4(lua_State* L) { } addr = g_new(address,1); - alloc_address_tvb(NULL,addr,AT_IPv4,sizeof(guint32),tvbr->tvb->ws_tvb,tvbr->offset); + alloc_address_tvb(NULL,addr,AT_IPv4,sizeof(uint32_t),tvbr->tvb->ws_tvb,tvbr->offset); pushAddress(L,addr); WSLUA_RETURN(1); /* The IPv4 <<lua_class_Address,`Address`>> object. */ @@ -813,7 +807,7 @@ WSLUA_METHOD TvbRange_le_ipv4(lua_State* L) { /* Get an Little Endian IPv4 Address from a <<lua_class_TvbRange,`TvbRange`>>, as an <<lua_class_Address,`Address`>> object. */ TvbRange tvbr = checkTvbRange(L,1); Address addr; - guint32 ip_addr; + uint32_t ip_addr; if ( !(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -885,7 +879,7 @@ WSLUA_METHOD TvbRange_nstime(lua_State* L) { #define WSLUA_OPTARG_TvbRange_nstime_ENCODING 2 /* An optional ENC_* encoding value to use */ TvbRange tvbr = checkTvbRange(L,1); NSTime nstime; - const guint encoding = (guint) luaL_optinteger(L, WSLUA_OPTARG_TvbRange_nstime_ENCODING, 0); + const unsigned encoding = (unsigned) luaL_optinteger(L, WSLUA_OPTARG_TvbRange_nstime_ENCODING, 0); if ( !(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -916,7 +910,7 @@ WSLUA_METHOD TvbRange_nstime(lua_State* L) { lua_pushinteger(L, tvbr->len); } else { - gint endoff = 0; + int endoff = 0; nstime_t *retval = tvb_get_string_time(tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, nstime, &endoff); if (!retval || endoff == 0) { @@ -968,7 +962,7 @@ WSLUA_METHOD TvbRange_string(lua_State* L) { /* Obtain a string from a <<lua_class_TvbRange,`TvbRange`>>. */ #define WSLUA_OPTARG_TvbRange_string_ENCODING 2 /* The encoding to use. Defaults to ENC_ASCII. */ TvbRange tvbr = checkTvbRange(L,1); - guint encoding = (guint)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_string_ENCODING, ENC_ASCII|ENC_NA); + unsigned encoding = (unsigned)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_string_ENCODING, ENC_ASCII|ENC_NA); char * str; if ( !(tvbr && tvbr->tvb)) return 0; @@ -977,17 +971,17 @@ WSLUA_METHOD TvbRange_string(lua_State* L) { return 0; } - str = (gchar*)tvb_get_string_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,encoding); + str = (char*)tvb_get_string_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,encoding); lua_pushlstring(L, str, strlen(str)); wmem_free(NULL, str); WSLUA_RETURN(1); /* A string containing all bytes in the <<lua_class_TvbRange,`TvbRange`>> including all zeroes (e.g., "a\000bc\000"). */ } -static int TvbRange_ustring_any(lua_State* L, gboolean little_endian) { +static int TvbRange_ustring_any(lua_State* L, bool little_endian) { /* Obtain a UTF-16 encoded string from a <<lua_class_TvbRange,`TvbRange`>>. */ TvbRange tvbr = checkTvbRange(L,1); - gchar * str; + char * str; if ( !(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -995,7 +989,7 @@ static int TvbRange_ustring_any(lua_State* L, gboolean little_endian) { return 0; } - str = (gchar*)tvb_get_string_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN)); + str = (char*)tvb_get_string_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN)); lua_pushlstring(L, str, strlen(str)); wmem_free(NULL, str); @@ -1004,22 +998,22 @@ static int TvbRange_ustring_any(lua_State* L, gboolean little_endian) { WSLUA_METHOD TvbRange_ustring(lua_State* L) { /* Obtain a Big Endian (network order) UTF-16 encoded string from a <<lua_class_TvbRange,`TvbRange`>>. */ - WSLUA_RETURN(TvbRange_ustring_any(L, FALSE)); /* A string containing all bytes in the <<lua_class_TvbRange,`TvbRange`>> including all zeroes (e.g., "a\000bc\000"). */ + WSLUA_RETURN(TvbRange_ustring_any(L, false)); /* A string containing all bytes in the <<lua_class_TvbRange,`TvbRange`>> including all zeroes (e.g., "a\000bc\000"). */ } WSLUA_METHOD TvbRange_le_ustring(lua_State* L) { /* Obtain a Little Endian UTF-16 encoded string from a <<lua_class_TvbRange,`TvbRange`>>. */ - WSLUA_RETURN(TvbRange_ustring_any(L, TRUE)); /* A string containing all bytes in the <<lua_class_TvbRange,`TvbRange`>> including all zeroes (e.g., "a\000bc\000"). */ + WSLUA_RETURN(TvbRange_ustring_any(L, true)); /* A string containing all bytes in the <<lua_class_TvbRange,`TvbRange`>> including all zeroes (e.g., "a\000bc\000"). */ } WSLUA_METHOD TvbRange_stringz(lua_State* L) { /* Obtain a zero terminated string from a <<lua_class_TvbRange,`TvbRange`>>. */ #define WSLUA_OPTARG_TvbRange_stringz_ENCODING 2 /* The encoding to use. Defaults to ENC_ASCII. */ TvbRange tvbr = checkTvbRange(L,1); - guint encoding = (guint)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_stringz_ENCODING, ENC_ASCII|ENC_NA); - gint offset; + unsigned encoding = (unsigned)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_stringz_ENCODING, ENC_ASCII|ENC_NA); + int offset; gunichar2 uchar; - gchar *str; + char *str; if ( !(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -1044,14 +1038,14 @@ WSLUA_METHOD TvbRange_stringz(lua_State* L) { break; default: - if (tvb_find_guint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) { + if (tvb_find_uint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) { luaL_error(L,"out of bounds"); return 0; } break; } - str = (gchar*)tvb_get_stringz_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,NULL,encoding); + str = (char*)tvb_get_stringz_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,NULL,encoding); lua_pushstring(L, str); wmem_free(NULL, str); @@ -1061,14 +1055,11 @@ WSLUA_METHOD TvbRange_stringz(lua_State* L) { WSLUA_METHOD TvbRange_strsize(lua_State* L) { /* Find the size of a zero terminated string from a <<lua_class_TvbRange,`TvbRange`>>. - The size of the string includes the terminating zero. - - @since 1.11.3 - */ + The size of the string includes the terminating zero. */ #define WSLUA_OPTARG_TvbRange_strsize_ENCODING 2 /* The encoding to use. Defaults to ENC_ASCII. */ TvbRange tvbr = checkTvbRange(L,1); - guint encoding = (guint)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_strsize_ENCODING, ENC_ASCII|ENC_NA); - gint offset; + unsigned encoding = (unsigned)luaL_optinteger(L,WSLUA_OPTARG_TvbRange_strsize_ENCODING, ENC_ASCII|ENC_NA); + int offset; gunichar2 uchar; if ( !(tvbr && tvbr->tvb)) return 0; @@ -1095,7 +1086,7 @@ WSLUA_METHOD TvbRange_strsize(lua_State* L) { break; default: - if (tvb_find_guint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) { + if (tvb_find_uint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) { luaL_error(L,"out of bounds"); return 0; } @@ -1107,13 +1098,13 @@ WSLUA_METHOD TvbRange_strsize(lua_State* L) { } -static int TvbRange_ustringz_any(lua_State* L, gboolean little_endian) { +static int TvbRange_ustringz_any(lua_State* L, bool little_endian) { /* Obtain a zero terminated string from a TvbRange */ - gint count; + int count; TvbRange tvbr = checkTvbRange(L,1); - gint offset; + int offset; gunichar2 uchar; - gchar *str; + char *str; if ( !(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -1132,7 +1123,7 @@ static int TvbRange_ustringz_any(lua_State* L, gboolean little_endian) { offset += 2; } while (uchar != 0); - str = (gchar*)tvb_get_stringz_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,&count, + str = (char*)tvb_get_stringz_enc(NULL,tvbr->tvb->ws_tvb,tvbr->offset,&count, (little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN)); lua_pushstring(L, str); lua_pushinteger(L,count); @@ -1143,12 +1134,12 @@ static int TvbRange_ustringz_any(lua_State* L, gboolean little_endian) { WSLUA_METHOD TvbRange_ustringz(lua_State* L) { /* Obtain a Big Endian (network order) UTF-16 encoded zero terminated string from a <<lua_class_TvbRange,`TvbRange`>>. */ - WSLUA_RETURN(TvbRange_ustringz_any(L, FALSE)); /* Two return values: the zero terminated string, and the length. */ + WSLUA_RETURN(TvbRange_ustringz_any(L, false)); /* Two return values: the zero terminated string, and the length. */ } WSLUA_METHOD TvbRange_le_ustringz(lua_State* L) { /* Obtain a Little Endian UTF-16 encoded zero terminated string from a TvbRange */ - WSLUA_RETURN(TvbRange_ustringz_any(L, TRUE)); /* Two return values: the zero terminated string, and the length. */ + WSLUA_RETURN(TvbRange_ustringz_any(L, true)); /* Two return values: the zero terminated string, and the length. */ } WSLUA_METHOD TvbRange_bytes(lua_State* L) { @@ -1173,8 +1164,8 @@ WSLUA_METHOD TvbRange_bytes(lua_State* L) { #define WSLUA_OPTARG_TvbRange_bytes_ENCODING 2 /* An optional ENC_* encoding value to use */ TvbRange tvbr = checkTvbRange(L,1); GByteArray* ba; - guint8* raw; - const guint encoding = (guint)luaL_optinteger(L, WSLUA_OPTARG_TvbRange_bytes_ENCODING, 0); + uint8_t* raw; + const unsigned encoding = (unsigned)luaL_optinteger(L, WSLUA_OPTARG_TvbRange_bytes_ENCODING, 0); if ( !(tvbr && tvbr->tvb)) return 0; @@ -1185,7 +1176,7 @@ WSLUA_METHOD TvbRange_bytes(lua_State* L) { if (encoding == 0) { ba = g_byte_array_new(); - raw = (guint8 *)tvb_memdup(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len); + raw = (uint8_t *)tvb_memdup(NULL,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len); g_byte_array_append(ba,raw,tvbr->len); wmem_free(NULL, raw); pushByteArray(L,ba); @@ -1195,14 +1186,14 @@ WSLUA_METHOD TvbRange_bytes(lua_State* L) { WSLUA_OPTARG_ERROR(TvbRange_nstime, ENCODING, "invalid encoding value"); } else { - gint endoff = 0; + int endoff = 0; GByteArray* retval; ba = g_byte_array_new(); retval = tvb_get_string_bytes(tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding, ba, &endoff); if (!retval || endoff == 0) { - g_byte_array_free(ba, TRUE); + g_byte_array_free(ba, true); /* push nil nstime and offset */ lua_pushnil(L); lua_pushnil(L); @@ -1237,16 +1228,16 @@ WSLUA_METHOD TvbRange_bitfield(lua_State* L) { } if (len <= 8) { - lua_pushnumber(L,(lua_Number)(guint)tvb_get_bits8(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len)); + lua_pushinteger(L,(lua_Integer)(unsigned)tvb_get_bits8(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len)); return 1; } else if (len <= 16) { - lua_pushnumber(L,tvb_get_bits16(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); + lua_pushinteger(L,tvb_get_bits16(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, false)); return 1; } else if (len <= 32) { - lua_pushnumber(L,tvb_get_bits32(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); + lua_pushinteger(L,tvb_get_bits32(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, false)); return 1; } else if (len <= 64) { - pushUInt64(L,tvb_get_bits64(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, FALSE)); + pushUInt64(L,tvb_get_bits64(tvbr->tvb->ws_tvb,tvbr->offset*8 + pos, len, false)); WSLUA_RETURN(1); /* The bitfield value */ } else { luaL_error(L,"TvbRange:bitfield() does not handle %d bits",len); @@ -1284,12 +1275,14 @@ WSLUA_METHOD TvbRange_range(lua_State* L) { return 0; } -WSLUA_METHOD TvbRange_uncompress(lua_State* L) { - /* Obtain an uncompressed <<lua_class_TvbRange,`TvbRange`>> from a <<lua_class_TvbRange,`TvbRange`>> */ -#define WSLUA_ARG_TvbRange_uncompress_NAME 2 /* The name to be given to the new data-source. */ +WSLUA_METHOD TvbRange_uncompress_zlib(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing zlib compressed data, decompresses the data and returns a new <<lua_class_TvbRange,`TvbRange`>> containing the uncompressed data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_uncompress_zlib_NAME 2 /* The name to be given to the new data-source. */ TvbRange tvbr = checkTvbRange(L,1); -#ifdef HAVE_ZLIB - const gchar* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_NAME,"Uncompressed"); +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_zlib_NAME,"Uncompressed"); tvbuff_t *uncompr_tvb; #endif @@ -1300,8 +1293,8 @@ WSLUA_METHOD TvbRange_uncompress(lua_State* L) { return 0; } -#ifdef HAVE_ZLIB - uncompr_tvb = tvb_child_uncompress(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) + uncompr_tvb = tvb_child_uncompress_zlib(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); if (uncompr_tvb) { add_new_data_source (lua_pinfo, uncompr_tvb, name); if (push_TvbRange(L,uncompr_tvb,0,tvb_captured_length(uncompr_tvb))) { @@ -1315,6 +1308,12 @@ WSLUA_METHOD TvbRange_uncompress(lua_State* L) { return 0; } +WSLUA_METHOD TvbRange_uncompress(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing zlib compressed data, decompresses the data and returns a new <<lua_class_TvbRange,`TvbRange`>> containing the uncompressed data. Deprecated; use tvbrange:uncompress_zlib() instead. */ +#define WSLUA_ARG_TvbRange_uncompress_NAME 2 /* The name to be given to the new data-source. */ + return TvbRange_uncompress_zlib(L); +} + /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */ static int TvbRange__gc(lua_State* L) { TvbRange tvbr = checkTvbRange(L,1); @@ -1325,6 +1324,267 @@ static int TvbRange__gc(lua_State* L) { } +WSLUA_METHOD TvbRange_uncompress_brotli(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing Brotli compressed data, decompresses the data and returns a new <<lua_class_TvbRange,`TvbRange`>> containing the uncompressed data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_uncompress_brotli_NAME 2 /* The name to be given to the new data-source. */ + TvbRange tvbr = checkTvbRange(L,1); +#ifdef HAVE_BROTLI + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_brotli_NAME,"Uncompressed"); + tvbuff_t *uncompr_tvb; +#endif + + if (!(tvbr && tvbr->tvb)) return 0; + + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + +#ifdef HAVE_BROTLI + uncompr_tvb = tvb_child_uncompress_brotli(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); + if (uncompr_tvb) { + add_new_data_source (lua_pinfo, uncompr_tvb, name); + if (push_TvbRange(L,uncompr_tvb,0,tvb_captured_length(uncompr_tvb))) { + WSLUA_RETURN(1); /* The <<lua_class_TvbRange,`TvbRange`>>. */ + } + } +#else + luaL_error(L,"Missing support for Brotli"); +#endif + + return 0; +} + +WSLUA_METHOD TvbRange_uncompress_hpack_huff(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing data compressed using the Huffman encoding in HTTP/2 HPACK and HTTP/3 QPACK, decompresses the data and returns a new <<lua_class_TvbRange,`TvbRange`>> containing the uncompressed data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_uncompress_hpack_huff_NAME 2 /* The name to be given to the new data-source. */ + TvbRange tvbr = checkTvbRange(L,1); + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_hpack_huff_NAME,"Uncompressed"); + tvbuff_t *uncompr_tvb; + + if (!(tvbr && tvbr->tvb)) return 0; + + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + + uncompr_tvb = tvb_child_uncompress_hpack_huff(tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); + if (uncompr_tvb) { + add_new_data_source (lua_pinfo, uncompr_tvb, name); + if (push_TvbRange(L,uncompr_tvb,0,tvb_captured_length(uncompr_tvb))) { + WSLUA_RETURN(1); /* The <<lua_class_TvbRange,`TvbRange`>>. */ + } + } + + return 0; +} + +WSLUA_METHOD TvbRange_uncompress_lz77(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing Microsoft Plain LZ77 compressed data, decompresses the data and returns a new <<lua_class_TvbRange,`TvbRange`>> containing the uncompressed data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_uncompress_lz77_NAME 2 /* The name to be given to the new data-source. */ + TvbRange tvbr = checkTvbRange(L,1); + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_lz77_NAME,"Uncompressed"); + tvbuff_t *uncompr_tvb; + + if (!(tvbr && tvbr->tvb)) return 0; + + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + + uncompr_tvb = tvb_child_uncompress_lz77(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); + if (uncompr_tvb) { + add_new_data_source (lua_pinfo, uncompr_tvb, name); + if (push_TvbRange(L,uncompr_tvb,0,tvb_captured_length(uncompr_tvb))) { + WSLUA_RETURN(1); /* The <<lua_class_TvbRange,`TvbRange`>>. */ + } + } + + return 0; +} + +WSLUA_METHOD TvbRange_uncompress_lz77huff(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing Microsoft LZ77+Huffman compressed data, decompresses the data and returns a new <<lua_class_TvbRange,`TvbRange`>> containing the uncompressed data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_uncompress_lz77huff_NAME 2 /* The name to be given to the new data-source. */ + TvbRange tvbr = checkTvbRange(L,1); + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_lz77huff_NAME,"Uncompressed"); + tvbuff_t *uncompr_tvb; + + if (!(tvbr && tvbr->tvb)) return 0; + + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + + uncompr_tvb = tvb_child_uncompress_lz77huff(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); + if (uncompr_tvb) { + add_new_data_source (lua_pinfo, uncompr_tvb, name); + if (push_TvbRange(L,uncompr_tvb,0,tvb_captured_length(uncompr_tvb))) { + WSLUA_RETURN(1); /* The <<lua_class_TvbRange,`TvbRange`>>. */ + } + } + + return 0; +} + +WSLUA_METHOD TvbRange_uncompress_lznt1(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing Microsoft LZNT1 compressed data, decompresses the data and returns a new <<lua_class_TvbRange,`TvbRange`>> containing the uncompressed data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_uncompress_lznt1_NAME 2 /* The name to be given to the new data-source. */ + TvbRange tvbr = checkTvbRange(L,1); + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_lznt1_NAME,"Uncompressed"); + tvbuff_t *uncompr_tvb; + + if (!(tvbr && tvbr->tvb)) return 0; + + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + + uncompr_tvb = tvb_child_uncompress_lznt1(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); + if (uncompr_tvb) { + add_new_data_source (lua_pinfo, uncompr_tvb, name); + if (push_TvbRange(L,uncompr_tvb,0,tvb_captured_length(uncompr_tvb))) { + WSLUA_RETURN(1); /* The <<lua_class_TvbRange,`TvbRange`>>. */ + } + } + + return 0; +} + +WSLUA_METHOD TvbRange_uncompress_snappy(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing Snappy compressed data, decompresses the data and returns a new <<lua_class_TvbRange,`TvbRange`>> containing the uncompressed data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_uncompress_snappy_NAME 2 /* The name to be given to the new data-source. */ + TvbRange tvbr = checkTvbRange(L,1); +#ifdef HAVE_SNAPPY + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_snappy_NAME,"Uncompressed"); + tvbuff_t *uncompr_tvb; +#endif + + if (!(tvbr && tvbr->tvb)) return 0; + + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + +#ifdef HAVE_SNAPPY + uncompr_tvb = tvb_child_uncompress_snappy(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); + if (uncompr_tvb) { + add_new_data_source (lua_pinfo, uncompr_tvb, name); + if (push_TvbRange(L,uncompr_tvb,0,tvb_captured_length(uncompr_tvb))) { + WSLUA_RETURN(1); /* The <<lua_class_TvbRange,`TvbRange`>>. */ + } + } +#else + luaL_error(L,"Missing support for Snappy"); +#endif + + return 0; +} + +WSLUA_METHOD TvbRange_uncompress_zstd(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing Zstandard compressed data, decompresses the data and returns a new <<lua_class_TvbRange,`TvbRange`>> containing the uncompressed data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_uncompress_zstd_NAME 2 /* The name to be given to the new data-source. */ + TvbRange tvbr = checkTvbRange(L,1); +#ifdef HAVE_ZSTD + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_zstd_NAME,"Uncompressed"); + tvbuff_t *uncompr_tvb; +#endif + + if (!(tvbr && tvbr->tvb)) return 0; + + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + +#ifdef HAVE_ZSTD + uncompr_tvb = tvb_child_uncompress_zstd(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); + if (uncompr_tvb) { + add_new_data_source (lua_pinfo, uncompr_tvb, name); + if (push_TvbRange(L,uncompr_tvb,0,tvb_captured_length(uncompr_tvb))) { + WSLUA_RETURN(1); /* The <<lua_class_TvbRange,`TvbRange`>>. */ + } + } +#else + luaL_error(L,"Missing support for ZStandard"); +#endif + + return 0; +} + +WSLUA_METHOD TvbRange_decode_base64(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing Base64 encoded data, return a new <<lua_class_TvbRange,`TvbRange`>> containing the decoded data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_decode_base64_NAME 2 /* The name to be given to the new data-source. */ + TvbRange tvbr = checkTvbRange(L,1); + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_decode_base64_NAME,"Decoded"); + tvbuff_t *decoded_tvb; + + if (!(tvbr && tvbr->tvb)) return 0; + + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + + decoded_tvb = base64_tvb_to_new_tvb(tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); + if (decoded_tvb) { + add_new_data_source (lua_pinfo, decoded_tvb, name); + if (push_TvbRange(L,decoded_tvb,0,tvb_captured_length(decoded_tvb))) { + WSLUA_RETURN(1); /* The <<lua_class_TvbRange,`TvbRange`>>. */ + } + } + + return 0; +} + +WSLUA_METHOD TvbRange_decode_base64url(lua_State* L) { + /* Given a <<lua_class_TvbRange,`TvbRange`>> containing base64url encoded data, return a new <<lua_class_TvbRange,`TvbRange`>> containing the decoded data. + @since 4.3.0 + */ +#define WSLUA_ARG_TvbRange_decode_base64url_NAME 2 /* The name to be given to the new data-source. */ + TvbRange tvbr = checkTvbRange(L,1); + const char* name = luaL_optstring(L,WSLUA_ARG_TvbRange_decode_base64url_NAME,"Decoded"); + tvbuff_t *decoded_tvb; + + if (!(tvbr && tvbr->tvb)) return 0; + + if (tvbr->tvb->expired) { + luaL_error(L,"expired tvb"); + return 0; + } + + decoded_tvb = base64uri_tvb_to_new_tvb(tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); + if (decoded_tvb) { + add_new_data_source (lua_pinfo, decoded_tvb, name); + if (push_TvbRange(L,decoded_tvb,0,tvb_captured_length(decoded_tvb))) { + WSLUA_RETURN(1); /* The <<lua_class_TvbRange,`TvbRange`>>. */ + } + } + + return 0; +} + WSLUA_METHOD TvbRange_len(lua_State* L) { /* Obtain the length of a <<lua_class_TvbRange,`TvbRange`>>. */ TvbRange tvbr = checkTvbRange(L,1); @@ -1334,7 +1594,7 @@ WSLUA_METHOD TvbRange_len(lua_State* L) { luaL_error(L,"expired tvb"); return 0; } - lua_pushnumber(L,(lua_Number)tvbr->len); + lua_pushinteger(L,(lua_Integer)tvbr->len); return 1; } @@ -1347,15 +1607,12 @@ WSLUA_METHOD TvbRange_offset(lua_State* L) { luaL_error(L,"expired tvb"); return 0; } - lua_pushnumber(L,(lua_Number)tvbr->offset); + lua_pushinteger(L,(lua_Integer)tvbr->offset); return 1; } WSLUA_METHOD TvbRange_raw(lua_State* L) { - /* Obtain a Lua string of the binary bytes in a <<lua_class_TvbRange,`TvbRange`>>. - - @since 1.11.3 - */ + /* Obtain a Lua string of the binary bytes in a <<lua_class_TvbRange,`TvbRange`>>. */ #define WSLUA_OPTARG_TvbRange_raw_OFFSET 2 /* The position of the first byte within the range. Default is 0, or first byte. */ #define WSLUA_OPTARG_TvbRange_raw_LENGTH 3 /* The length of the segment to get. Default is -1, or the remaining bytes in the range. */ TvbRange tvbr = checkTvbRange(L,1); @@ -1382,10 +1639,10 @@ WSLUA_METHOD TvbRange_raw(lua_State* L) { } if (len < 0) { luaL_error(L,"out of bounds"); - return FALSE; + return false; } else if ( (len + offset) > tvbr->len) { luaL_error(L,"Range is out of bounds"); - return FALSE; + return false; } lua_pushlstring(L, tvb_get_ptr(tvbr->tvb->ws_tvb, tvbr->offset+offset, len), len); @@ -1394,10 +1651,7 @@ WSLUA_METHOD TvbRange_raw(lua_State* L) { } WSLUA_METAMETHOD TvbRange__eq(lua_State* L) { - /* Checks whether the contents of two <<lua_class_TvbRange,`TvbRange`>>s are equal. - - @since 1.99.8 - */ + /* Checks whether the contents of two <<lua_class_TvbRange,`TvbRange`>>s are equal. */ TvbRange tvb_l = checkTvbRange(L,1); TvbRange tvb_r = checkTvbRange(L,2); @@ -1406,8 +1660,8 @@ WSLUA_METAMETHOD TvbRange__eq(lua_State* L) { tvb_l->len <= tvb_captured_length_remaining(tvb_l->tvb->ws_tvb, tvb_l->offset) && tvb_r->len <= tvb_captured_length_remaining(tvb_r->tvb->ws_tvb, tvb_r->offset)) { - const gchar* lp = tvb_get_ptr(tvb_l->tvb->ws_tvb, tvb_l->offset, tvb_l->len); - const gchar* rp = tvb_get_ptr(tvb_r->tvb->ws_tvb, tvb_r->offset, tvb_r->len); + const char* lp = tvb_get_ptr(tvb_l->tvb->ws_tvb, tvb_l->offset, tvb_l->len); + const char* rp = tvb_get_ptr(tvb_r->tvb->ws_tvb, tvb_r->offset, tvb_r->len); int i = 0; for (; i < tvb_r->len; ++i) { @@ -1480,6 +1734,16 @@ WSLUA_METHODS TvbRange_methods[] = { WSLUA_CLASS_FNREG(TvbRange,le_ustringz), WSLUA_CLASS_FNREG(TvbRange,ustringz), WSLUA_CLASS_FNREG(TvbRange,uncompress), + WSLUA_CLASS_FNREG(TvbRange,uncompress_zlib), + WSLUA_CLASS_FNREG(TvbRange,uncompress_brotli), + WSLUA_CLASS_FNREG(TvbRange,uncompress_hpack_huff), + WSLUA_CLASS_FNREG(TvbRange,uncompress_lz77), + WSLUA_CLASS_FNREG(TvbRange,uncompress_lz77huff), + WSLUA_CLASS_FNREG(TvbRange,uncompress_lznt1), + WSLUA_CLASS_FNREG(TvbRange,uncompress_snappy), + WSLUA_CLASS_FNREG(TvbRange,uncompress_zstd), + WSLUA_CLASS_FNREG(TvbRange,decode_base64), + WSLUA_CLASS_FNREG(TvbRange,decode_base64url), WSLUA_CLASS_FNREG(TvbRange,raw), { NULL, NULL } }; @@ -1493,6 +1757,9 @@ WSLUA_META TvbRange_meta[] = { }; int TvbRange_register(lua_State* L) { + if (outstanding_TvbRange != NULL) { + g_ptr_array_unref(outstanding_TvbRange); + } outstanding_TvbRange = g_ptr_array_new(); WSLUA_REGISTER_CLASS(TvbRange); return 0; diff --git a/epan/wslua/wslua_utility.c b/epan/wslua/wslua_utility.c index 3756c511..8ab81a60 100644 --- a/epan/wslua/wslua_utility.c +++ b/epan/wslua/wslua_utility.c @@ -11,6 +11,7 @@ */ #include "config.h" +#define WS_LOG_DOMAIN LOG_DOMAIN_WSLUA /* WSLUA_MODULE Utility Utility Functions */ @@ -22,15 +23,15 @@ WSLUA_FUNCTION wslua_get_version(lua_State* L) { /* Gets the Wireshark version as a string. */ - const gchar* str = VERSION; + const char* str = VERSION; lua_pushstring(L,str); WSLUA_RETURN(1); /* The version string, e.g. "3.2.5". */ } -static gchar* current_plugin_version = NULL; +static char* current_plugin_version = NULL; -const gchar* get_current_plugin_version(void) { +const char* get_current_plugin_version(void) { return current_plugin_version ? current_plugin_version : ""; } @@ -69,8 +70,6 @@ WSLUA_FUNCTION wslua_set_plugin_info(lua_State* L) { set_plugin_info(my_info) ---- - - @since 1.99.8 */ #define WSLUA_ARG_set_plugin_info_TABLE 1 /* The Lua table of information. */ @@ -99,11 +98,11 @@ WSLUA_FUNCTION wslua_format_date(lua_State* LS) { /* Formats an absolute timesta #define WSLUA_ARG_format_date_TIMESTAMP 1 /* A timestamp value to convert. */ lua_Number timestamp = luaL_checknumber(LS,WSLUA_ARG_format_date_TIMESTAMP); nstime_t then; - gchar* str; + char* str; then.secs = (time_t)(floor(timestamp)); - then.nsecs = (guint32) ( (timestamp-(double)(then.secs))*1000000000); - str = abs_time_to_str(NULL, &then, ABSOLUTE_TIME_LOCAL, TRUE); + then.nsecs = (uint32_t) ( (timestamp-(double)(then.secs))*1000000000); + str = abs_time_to_str(NULL, &then, ABSOLUTE_TIME_LOCAL, true); lua_pushstring(LS,str); wmem_free(NULL, str); @@ -114,10 +113,10 @@ WSLUA_FUNCTION wslua_format_time(lua_State* LS) { /* Formats a relative timestam #define WSLUA_ARG_format_time_TIMESTAMP 1 /* A timestamp value to convert. */ lua_Number timestamp = luaL_checknumber(LS,WSLUA_ARG_format_time_TIMESTAMP); nstime_t then; - gchar* str; + char* str; then.secs = (time_t)(floor(timestamp)); - then.nsecs = (guint32) ( (timestamp-(double)(then.secs))*1000000000); + then.nsecs = (uint32_t) ( (timestamp-(double)(then.secs))*1000000000); str = rel_time_to_str(NULL, &then); lua_pushstring(LS,str); wmem_free(NULL, str); @@ -126,13 +125,13 @@ WSLUA_FUNCTION wslua_format_time(lua_State* LS) { /* Formats a relative timestam } WSLUA_FUNCTION wslua_get_preference(lua_State *L) { - /* Get a preference value. @since 3.5.0 */ + /* Get a preference value. */ #define WSLUA_ARG_get_preference_PREFERENCE 1 /* The name of the preference. */ - const gchar* preference = luaL_checkstring(L,WSLUA_ARG_get_preference_PREFERENCE); + const char* preference = luaL_checkstring(L,WSLUA_ARG_get_preference_PREFERENCE); /* Split preference from module.preference */ - gchar *module_name = g_strdup(preference); - gchar *preference_name = strchr(module_name, '.'); + char *module_name = g_strdup(preference); + char *preference_name = strchr(module_name, '.'); pref_t *pref = NULL; if (preference_name) { @@ -148,20 +147,20 @@ WSLUA_FUNCTION wslua_get_preference(lua_State *L) { switch (prefs_get_type(pref)) { case PREF_UINT: { - guint uint_value = prefs_get_uint_value_real(pref, pref_current); + unsigned uint_value = prefs_get_uint_value_real(pref, pref_current); lua_pushinteger(L, uint_value); break; } case PREF_BOOL: { - gboolean bool_value = prefs_get_bool_value(pref, pref_current); + bool bool_value = prefs_get_bool_value(pref, pref_current); lua_pushboolean(L, bool_value); break; } case PREF_ENUM: { const enum_val_t *enums; - gint enum_value = prefs_get_enum_value(pref, pref_current); + int enum_value = prefs_get_enum_value(pref, pref_current); for (enums = prefs_get_enumvals(pref); enums->name; enums++) { if (enums->value == enum_value) { @@ -180,8 +179,9 @@ WSLUA_FUNCTION wslua_get_preference(lua_State *L) { case PREF_SAVE_FILENAME: case PREF_OPEN_FILENAME: case PREF_DIRNAME: + case PREF_DISSECTOR: { - const gchar *string_value = prefs_get_string_value(pref, pref_current); + const char *string_value = prefs_get_string_value(pref, pref_current); lua_pushstring(L,string_value); break; } @@ -205,14 +205,14 @@ WSLUA_FUNCTION wslua_get_preference(lua_State *L) { } WSLUA_FUNCTION wslua_set_preference(lua_State *L) { - /* Set a preference value. @since 3.5.0 */ + /* Set a preference value. */ #define WSLUA_ARG_set_preference_PREFERENCE 1 /* The name of the preference. */ #define WSLUA_ARG_set_preference_VALUE 2 /* The preference value to set. */ - const gchar* preference = luaL_checkstring(L,WSLUA_ARG_set_preference_PREFERENCE); + const char* preference = luaL_checkstring(L,WSLUA_ARG_set_preference_PREFERENCE); /* Split preference from module.preference */ - gchar *module_name = g_strdup(preference); - gchar *preference_name = strchr(module_name, '.'); + char *module_name = g_strdup(preference); + char *preference_name = strchr(module_name, '.'); module_t *module = NULL; pref_t *pref = NULL; @@ -230,7 +230,7 @@ WSLUA_FUNCTION wslua_set_preference(lua_State *L) { switch (prefs_get_type(pref)) { case PREF_UINT: { - guint uint_value = (guint)luaL_checkinteger(L,WSLUA_ARG_set_preference_VALUE); + unsigned uint_value = (unsigned)luaL_checkinteger(L,WSLUA_ARG_set_preference_VALUE); changed = prefs_set_uint_value(pref, uint_value, pref_current); module->prefs_changed_flags |= changed; lua_pushboolean(L, changed); @@ -238,7 +238,7 @@ WSLUA_FUNCTION wslua_set_preference(lua_State *L) { } case PREF_BOOL: { - gboolean bool_value = wslua_checkboolean(L, WSLUA_ARG_set_preference_VALUE); + bool bool_value = wslua_checkboolean(L, WSLUA_ARG_set_preference_VALUE); changed = prefs_set_bool_value(pref, bool_value, pref_current); module->prefs_changed_flags |= changed; lua_pushboolean(L, changed); @@ -246,7 +246,7 @@ WSLUA_FUNCTION wslua_set_preference(lua_State *L) { } case PREF_ENUM: { - const gchar *enum_value = luaL_checkstring(L,WSLUA_ARG_set_preference_VALUE); + const char *enum_value = luaL_checkstring(L,WSLUA_ARG_set_preference_VALUE); changed = prefs_set_enum_string_value(pref, enum_value, pref_current); module->prefs_changed_flags |= changed; lua_pushboolean(L, changed); @@ -256,8 +256,9 @@ WSLUA_FUNCTION wslua_set_preference(lua_State *L) { case PREF_SAVE_FILENAME: case PREF_OPEN_FILENAME: case PREF_DIRNAME: + case PREF_DISSECTOR: { - const gchar *string_value = luaL_checkstring(L,WSLUA_ARG_set_preference_VALUE); + const char *string_value = luaL_checkstring(L,WSLUA_ARG_set_preference_VALUE); changed = prefs_set_string_value(pref, string_value, pref_current); module->prefs_changed_flags |= changed; lua_pushboolean(L, changed); @@ -265,7 +266,7 @@ WSLUA_FUNCTION wslua_set_preference(lua_State *L) { } case PREF_RANGE: { - const gchar *range_value = luaL_checkstring(L,WSLUA_ARG_set_preference_VALUE); + const char *range_value = luaL_checkstring(L,WSLUA_ARG_set_preference_VALUE); range_t *range = NULL; convert_ret_t ret = range_convert_str(NULL, &range, range_value, prefs_get_max_value(pref)); if (ret == CVT_NUMBER_TOO_BIG) { @@ -292,13 +293,13 @@ WSLUA_FUNCTION wslua_set_preference(lua_State *L) { } WSLUA_FUNCTION wslua_reset_preference(lua_State *L) { - /* Reset a preference to default value. @since 3.5.0 */ + /* Reset a preference to default value. */ #define WSLUA_ARG_reset_preference_PREFERENCE 1 /* The name of the preference. */ - const gchar* preference = luaL_checkstring(L,WSLUA_ARG_reset_preference_PREFERENCE); + const char* preference = luaL_checkstring(L,WSLUA_ARG_reset_preference_PREFERENCE); // Split preference from module.preference - gchar *module_name = g_strdup(preference); - gchar *preference_name = strchr(module_name, '.'); + char *module_name = g_strdup(preference); + char *preference_name = strchr(module_name, '.'); pref_t *pref = NULL; if (preference_name) { @@ -311,7 +312,7 @@ WSLUA_FUNCTION wslua_reset_preference(lua_State *L) { if (pref) { reset_pref(pref); - lua_pushboolean(L, TRUE); + lua_pushboolean(L, true); } else { /* No such preference. */ lua_pushnil(L); @@ -322,13 +323,13 @@ WSLUA_FUNCTION wslua_reset_preference(lua_State *L) { } WSLUA_FUNCTION wslua_apply_preferences(lua_State *L) { - /* Write preferences to file and apply changes. @since 3.5.0 */ + /* Write preferences to file and apply changes. */ char *pf_path = NULL; int err = write_prefs(&pf_path); if (err) { /* Make a copy of pf_path because luaL_error() will return */ - gchar pf_path_copy[256]; + char pf_path_copy[256]; (void) g_strlcpy(pf_path_copy, pf_path, sizeof pf_path_copy); g_free(pf_path); @@ -343,7 +344,7 @@ WSLUA_FUNCTION wslua_apply_preferences(lua_State *L) { WSLUA_FUNCTION wslua_report_failure(lua_State* LS) { /* Reports a failure to the user. */ #define WSLUA_ARG_report_failure_TEXT 1 /* Message text to report. */ - const gchar* s = luaL_checkstring(LS,WSLUA_ARG_report_failure_TEXT); + const char* s = luaL_checkstring(LS,WSLUA_ARG_report_failure_TEXT); report_failure("%s",s); return 0; } @@ -372,7 +373,7 @@ char* wslua_get_actual_filename(const char* fname) { return g_strdup(fname_clean); } - filename = get_persconffile_path(fname_clean,FALSE); + filename = get_persconffile_path(fname_clean,false); if ( file_exists(filename) ) { return filename; @@ -393,10 +394,48 @@ char* wslua_get_actual_filename(const char* fname) { return NULL; } +WSLUA_FUNCTION wslua_dofile(lua_State* L) { + /* + Loads a Lua file and executes it as a Lua chunk, similar to the standard + https://www.lua.org/manual/5.4/manual.html#pdf-dofile[dofile] + but searches additional directories. + The search order is the current directory, followed by the user's + https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html[personal configuration] + directory, and finally the + https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html[global configuration] + directory. + + [TIP] + .The configuration directories are not the plugin directories. + ==== + The configuration directories searched are not the global and personal plugin + directories. All Lua files in the plugin directories are loaded at startup; + `dofile` is for loading files from additional locations. + The file path can be absolute or relative to one of the search directories. + ==== + + */ +#define WSLUA_ARG_dofile_FILENAME 1 /* Name of the file to be run. If the file does not exist in the current directory, the user and system directories are searched. */ + const char *given_fname = luaL_checkstring(L, WSLUA_ARG_dofile_FILENAME); + char* filename = wslua_get_actual_filename(given_fname); + int n; + + if (!filename) { + WSLUA_ARG_ERROR(dofile,FILENAME,"file does not exist"); + return 0; + } + + n = lua_gettop(L); + if (luaL_loadfile(L, filename) != 0) lua_error(L); + g_free(filename); + lua_call(L, 0, LUA_MULTRET); + return lua_gettop(L) - n; +} + WSLUA_FUNCTION wslua_loadfile(lua_State* L) { /* Loads a Lua file and compiles it into a Lua chunk, similar to the standard - https://www.lua.org/manual/5.1/manual.html#pdf-loadfile[loadfile] + https://www.lua.org/manual/5.4/manual.html#pdf-loadfile[loadfile] but searches additional directories. The search order is the current directory, followed by the user's https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html[personal configuration] @@ -440,35 +479,6 @@ WSLUA_FUNCTION wslua_loadfile(lua_State* L) { } } -WSLUA_FUNCTION wslua_dofile(lua_State* L) { - /* - Loads a Lua file and executes it as a Lua chunk, similar to the standard - https://www.lua.org/manual/5.1/manual.html#pdf-dofile[dofile] - but searches additional directories. - The search order is the current directory, followed by the user's - https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html[personal configuration] - directory, and finally the - https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html[global configuration] - directory. - */ -#define WSLUA_ARG_dofile_FILENAME 1 /* Name of the file to be run. If the file does not exist in the current directory, the user and system directories are searched. */ - const char *given_fname = luaL_checkstring(L, WSLUA_ARG_dofile_FILENAME); - char* filename = wslua_get_actual_filename(given_fname); - int n; - - if (!filename) { - WSLUA_ARG_ERROR(dofile,FILENAME,"file does not exist"); - return 0; - } - - n = lua_gettop(L); - if (luaL_loadfile(L, filename) != 0) lua_error(L); - g_free(filename); - lua_call(L, 0, LUA_MULTRET); - return lua_gettop(L) - n; -} - - typedef struct _statcmd_t { lua_State* L; int func_ref; diff --git a/epan/wslua/wslua_wtap.c b/epan/wslua/wslua_wtap.c index 524ed7c3..147b774a 100644 --- a/epan/wslua/wslua_wtap.c +++ b/epan/wslua/wslua_wtap.c @@ -30,8 +30,6 @@ WSLUA_FUNCTION wslua_wtap_file_type_subtype_description(lua_State* LS) { /* Get a string describing a capture file type, given a filetype value for that file type. - - @since 3.2.12, 3.4.4 */ #define WSLUA_ARG_wtap_file_type_subtype_description_FILETYPE 1 /* The type for which the description is to be fetched - a number returned by `wtap_name_to_file_type_subtype()`. */ lua_Number filetype = luaL_checknumber(LS,WSLUA_ARG_wtap_file_type_subtype_description_FILETYPE); @@ -40,7 +38,7 @@ WSLUA_FUNCTION wslua_wtap_file_type_subtype_description(lua_State* LS) { /* Too big. */ lua_pushnil(LS); } else { - const gchar* str = wtap_file_type_subtype_description((int)filetype); + const char* str = wtap_file_type_subtype_description((int)filetype); if (str == NULL) lua_pushnil(LS); else @@ -53,8 +51,6 @@ WSLUA_FUNCTION wslua_wtap_file_type_subtype_name(lua_State* LS) { /* Get a string giving the name for a capture file type, given a filetype value for that file type. - - @since 3.2.12, 3.4.4 */ #define WSLUA_ARG_wtap_file_type_subtype_name_FILETYPE 1 /* The type for which the name is to be fetched - a number returned by `wtap_name_to_file_type_subtype()`. */ lua_Number filetype = luaL_checknumber(LS,WSLUA_ARG_wtap_file_type_subtype_name_FILETYPE); @@ -63,7 +59,7 @@ WSLUA_FUNCTION wslua_wtap_file_type_subtype_name(lua_State* LS) { /* Too big. */ lua_pushnil(LS); } else { - const gchar* str = wtap_file_type_subtype_name((int)filetype); + const char* str = wtap_file_type_subtype_name((int)filetype); if (str == NULL) lua_pushnil(LS); else @@ -76,8 +72,6 @@ WSLUA_FUNCTION wslua_wtap_name_to_file_type_subtype(lua_State* LS) { /* Get a filetype value for a file type, given the name for that file type. - - @since 3.2.12, 3.4.4 */ #define WSLUA_ARG_wtap_name_to_file_type_subtype_NAME 1 /* The name of a file type. */ const char* name = luaL_checkstring(LS,WSLUA_ARG_wtap_name_to_file_type_subtype_NAME); @@ -85,40 +79,28 @@ WSLUA_FUNCTION wslua_wtap_name_to_file_type_subtype(lua_State* LS) { if (filetype == -1) lua_pushnil(LS); else - lua_pushnumber(LS,filetype); + lua_pushinteger(LS,filetype); WSLUA_RETURN(1); /* The filetype value for the file type with that name, or nil if there is no such file type. */ } WSLUA_FUNCTION wslua_wtap_pcap_file_type_subtype(lua_State* LS) { - /* - Get the filetype value for pcap files. - - @since 3.2.12, 3.4.4 - */ + /* Get the filetype value for pcap files. */ lua_Number filetype = wtap_pcap_file_type_subtype(); - lua_pushnumber(LS,filetype); + lua_pushinteger(LS,filetype); WSLUA_RETURN(1); /* The filetype value for pcap files. */ } WSLUA_FUNCTION wslua_wtap_pcap_nsec_file_type_subtype(lua_State* LS) { - /* - Get the filetype value for nanosecond-resolution pcap files. - - @since 3.2.12, 3.4.4 - */ + /* Get the filetype value for nanosecond-resolution pcap files. */ lua_Number filetype = wtap_pcap_nsec_file_type_subtype(); - lua_pushnumber(LS,filetype); + lua_pushinteger(LS,filetype); WSLUA_RETURN(1); /* The filetype value for nanosecond-resolution pcap files. */ } WSLUA_FUNCTION wslua_wtap_pcapng_file_type_subtype(lua_State* LS) { - /* - Get the filetype value for pcapng files. - - @since 3.2.12, 3.4.4 - */ + /* Get the filetype value for pcapng files. */ lua_Number filetype = wtap_pcapng_file_type_subtype(); - lua_pushnumber(LS,filetype); + lua_pushinteger(LS,filetype); WSLUA_RETURN(1); /* The filetype value for pcapng files. */ } @@ -135,7 +117,7 @@ extern void wslua_init_wtap_filetypes(lua_State* LS) { * so none of the entries will be in a sequence. */ lua_createtable(LS,0,table->len); - for (guint i = 0; i < table->len; i++) { + for (unsigned i = 0; i < table->len; i++) { struct backwards_compatibiliity_lua_name *entry; entry = &g_array_index(table, @@ -148,7 +130,7 @@ extern void wslua_init_wtap_filetypes(lua_State* LS) { * it. */ lua_pushstring(LS, entry->name); - lua_pushnumber(LS, entry->ft); + lua_pushinteger(LS, entry->ft); /* * The -3 is the index, relative to the top of the stack, of * the table; the two elements on top of it are the ft and |