summaryrefslogtreecommitdiffstats
path: root/epan/wslua/wslua_frame_info.c
diff options
context:
space:
mode:
Diffstat (limited to 'epan/wslua/wslua_frame_info.c')
-rw-r--r--epan/wslua/wslua_frame_info.c91
1 files changed, 44 insertions, 47 deletions
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),