Skip to content

Commit

Permalink
wslua: expose some libwiretap APIs in Lua.
Browse files Browse the repository at this point in the history
Provide Lua version of wtap_file_type_subtype_string(),
wtap_file_type_subtype_short_string(), and
wtap_short_string_to_file_type_subtype().

This will be backported to the 3.2 and 3.4 branches, to allow scripts
not run on the bleeding-edge version to use them.
  • Loading branch information
guyharris committed Feb 13, 2021
1 parent b67494e commit f0ebc50
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions docbook/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ set(WSLUA_MODULES
${CMAKE_SOURCE_DIR}/epan/wslua/wslua_frame_info.c
${CMAKE_SOURCE_DIR}/epan/wslua/wslua_capture_info.c
${CMAKE_SOURCE_DIR}/epan/wslua/wslua_dir.c
${CMAKE_SOURCE_DIR}/epan/wslua/wslua_wtap.c
${CMAKE_SOURCE_DIR}/epan/wslua/wslua_util.c
${CMAKE_SOURCE_DIR}/epan/wslua/wslua_struct.c
)
Expand Down
1 change: 1 addition & 0 deletions docbook/wsluarm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ include::{build_dir}/wsluarm_src/wslua_tree.adoc[]
include::{build_dir}/wsluarm_src/wslua_tvb.adoc[]
include::{build_dir}/wsluarm_src/wslua_file.adoc[]
include::{build_dir}/wsluarm_src/wslua_dir.adoc[]
include::{build_dir}/wsluarm_src/wslua_wtap.adoc[]
include::{build_dir}/wsluarm_src/wslua_util.adoc[]
include::{build_dir}/wsluarm_src/wslua_int64.adoc[]
include::{build_dir}/wsluarm_src/wslua_struct.adoc[]
Expand Down
1 change: 1 addition & 0 deletions epan/wslua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(WSLUA_MODULES
${CMAKE_CURRENT_SOURCE_DIR}/wslua_tree.c
${CMAKE_CURRENT_SOURCE_DIR}/wslua_tvb.c
${CMAKE_CURRENT_SOURCE_DIR}/wslua_util.c
${CMAKE_CURRENT_SOURCE_DIR}/wslua_wtap.c
)

set(WSLUA_FILES
Expand Down
85 changes: 85 additions & 0 deletions epan/wslua/wslua_wtap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* wslua_wtap.c
*
* Wireshark's interface to the Lua Programming Language
* for various libwiretap utility functions.
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <[email protected]>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "config.h"

/* WSLUA_MODULE Wtap Wtap Functions For Handling Capture File Types */

#include <limits.h>

#include "wslua.h"
#include <wiretap/wtap.h>

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_file_type_subtype_description_FILETYPE 1 /* The type for which the description is to be fetched - a number entry from the `wtap_filetypes` table in `init.lua`. */
lua_Number filetype = luaL_checknumber(LS,WSLUA_ARG_file_type_subtype_description_FILETYPE);
/* wtap_file_type_subtype_string()'s name isn't really descriptive. */
if (filetype > INT_MAX) {
/* Too big. */
lua_pushnil(LS);
} else {
const gchar* str = wtap_file_type_subtype_string((int)filetype);
if (str == NULL)
lua_pushnil(LS);
else
lua_pushstring(LS,str);
}
WSLUA_RETURN(1); /* The description of the file type with that filetype value, or nul if there is no such file type. */
}

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_file_type_subtype_name_FILETYPE 1 /* The type for which the name is to be fetched - a number entry from the `wtap_filetypes` table in `init.lua`. */
lua_Number filetype = luaL_checknumber(LS,WSLUA_ARG_file_type_subtype_name_FILETYPE);
/* wtap_file_type_subtype_string()'s name isn't really descriptive. */
if (filetype > INT_MAX) {
/* Too big. */
lua_pushnil(LS);
} else {
const gchar* str = wtap_file_type_subtype_short_string((int)filetype);
if (str == NULL)
lua_pushnil(LS);
else
lua_pushstring(LS,str);
}
WSLUA_RETURN(1); /* The name of the file type with that filetype value, or nul if there is no such file type. */
}

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_name_to_file_type_subtype_NAME 1 /* A timestamp value to convert. */
const char* name = luaL_checkstring(LS,WSLUA_ARG_name_to_file_type_subtype_NAME);
/* wtap_short_string_to_file_type_subtype()'s name isn't really descriptive. */
lua_Number filetype = wtap_short_string_to_file_type_subtype(name);
if (filetype == -1)
lua_pushnil(LS);
else
lua_pushnumber(LS,filetype);
WSLUA_RETURN(1); /* The filetype value for the file type with that name, or nil if there is no such file type. */
}

0 comments on commit f0ebc50

Please sign in to comment.