aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-01-25 20:17:21 -0500
committerMichael Mann <mmann78@netscape.net>2016-02-23 00:39:38 +0000
commit08d49ff2e06cb35dc9084735aa60c83686afdd9c (patch)
tree93d55773a42d4a1cf64b6544c6e2f3ec03ef4f4e /epan/wslua
parent37acf433dbb2ef1d443c9ee09a315b0b4ce136d8 (diff)
Making wiretap option blocks more generic.
This was inspired by https://code.wireshark.org/review/9729/, but takes it in a different direction where all options are put into an array, regardless of whether they are "standard" or "custom". It should be easier to add "custom" options in this design. Some, but not all blocks have been converted. Descriptions of some of the block options have been moved from wtap.h to pcapng.h as it seems to be the one that implements the description of the blocks. Also what could be added/refactored is registering block behavior. Change-Id: I3dffa38f0bb088f98749a4f97a3b7655baa4aa6a Reviewed-on: https://code.wireshark.org/review/13667 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/wslua')
-rw-r--r--epan/wslua/wslua.h21
-rw-r--r--epan/wslua/wslua_capture_info.c25
2 files changed, 34 insertions, 12 deletions
diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h
index 75b67967ed..5239f21fe7 100644
--- a/epan/wslua/wslua.h
+++ b/epan/wslua/wslua.h
@@ -554,6 +554,12 @@ extern int wslua_set__index(lua_State *L);
#define WSLUA_ATTRIBUTE_STRING_GETTER(C,member) \
WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,member,member)
+#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(C,name,member,option) \
+ WSLUA_ATTRIBUTE_GET(C,name, { \
+ char* str; \
+ wtap_optionblock_get_option_string(obj->member, option, &str); \
+ lua_pushstring(L,str); /* this pushes nil if obj->member is null */ \
+ })
#define WSLUA_ATTRIBUTE_SET(C,name,block) \
static int C##_set_##name (lua_State* L) { \
@@ -603,6 +609,21 @@ extern int wslua_set__index(lua_State *L);
#define WSLUA_ATTRIBUTE_STRING_SETTER(C,field,need_free) \
WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,field,need_free)
+#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; \
+ if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
+ s = g_strdup(lua_tostring(L,-1)); \
+ } else { \
+ return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
+ } \
+ wtap_optionblock_set_option_string(obj->member, option, s); \
+ return 0; \
+ } \
+ /* silly little trick so we can add a semicolon after this macro */ \
+ typedef void __dummy##C##_set_##field
+
#define WSLUA_ERROR(name,error) { luaL_error(L, "%s%s", #name ": " ,error); }
#define WSLUA_ARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); }
#define WSLUA_OPTARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); }
diff --git a/epan/wslua/wslua_capture_info.c b/epan/wslua/wslua_capture_info.c
index 7a4ca96341..ddba06d792 100644
--- a/epan/wslua/wslua_capture_info.c
+++ b/epan/wslua/wslua_capture_info.c
@@ -28,6 +28,7 @@
#include "wslua_file_common.h"
#include <epan/addr_resolv.h>
+#include <wiretap/pcapng.h>
/* WSLUA_CONTINUE_MODULE File */
@@ -111,23 +112,23 @@ WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(CaptureInfo,snapshot_length,wth->snapshot_le
/* WSLUA_ATTRIBUTE CaptureInfo_comment RW A string comment for the whole capture file,
or nil if there is no `comment`. */
-WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfo,comment,wth->shb_hdr.opt_comment);
-WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(CaptureInfo,comment,wth->shb_hdr.opt_comment,TRUE);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(CaptureInfo,comment,wth->shb_hdr,OPT_COMMENT);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(CaptureInfo,comment,wth->shb_hdr,OPT_COMMENT);
/* WSLUA_ATTRIBUTE CaptureInfo_hardware RW A string containing the description of
the hardware used to create the capture, or nil if there is no `hardware` string. */
-WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfo,hardware,wth->shb_hdr.shb_hardware);
-WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(CaptureInfo,hardware,wth->shb_hdr.shb_hardware,TRUE);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(CaptureInfo,hardware,wth->shb_hdr,OPT_SHB_HARDWARE);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(CaptureInfo,hardware,wth->shb_hdr,OPT_SHB_HARDWARE);
/* WSLUA_ATTRIBUTE CaptureInfo_os RW A string containing the name of
the operating system used to create the capture, or nil if there is no `os` string. */
-WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfo,os,wth->shb_hdr.shb_os);
-WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(CaptureInfo,os,wth->shb_hdr.shb_os,TRUE);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(CaptureInfo,os,wth->shb_hdr,OPT_SHB_OS);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(CaptureInfo,os,wth->shb_hdr,OPT_SHB_OS);
/* WSLUA_ATTRIBUTE CaptureInfo_user_app RW A string containing the name of
the application used to create the capture, or nil if there is no `user_app` string. */
-WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfo,user_app,wth->shb_hdr.shb_user_appl);
-WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(CaptureInfo,user_app,wth->shb_hdr.shb_user_appl,TRUE);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(CaptureInfo,user_app,wth->shb_hdr,OPT_SHB_USERAPPL);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(CaptureInfo,user_app,wth->shb_hdr,OPT_SHB_USERAPPL);
/* WSLUA_ATTRIBUTE CaptureInfo_hosts WO Sets resolved ip-to-hostname information.
@@ -354,19 +355,19 @@ WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(CaptureInfoConst,encap,wdh->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. */
-WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfoConst,comment,wth->shb_hdr.opt_comment);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(CaptureInfoConst,comment,wth->shb_hdr,OPT_COMMENT);
/* WSLUA_ATTRIBUTE CaptureInfoConst_hardware RO A string containing the description of
the hardware used to create the capture, or nil if there is no hardware string. */
-WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfoConst,hardware,wth->shb_hdr.shb_hardware);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(CaptureInfoConst,hardware,wth->shb_hdr,OPT_SHB_HARDWARE);
/* WSLUA_ATTRIBUTE CaptureInfoConst_os RO A string containing the name of
the operating system used to create the capture, or nil if there is no os string. */
-WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfoConst,os,wth->shb_hdr.shb_os);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(CaptureInfoConst,os,wth->shb_hdr,OPT_SHB_OS);
/* WSLUA_ATTRIBUTE CaptureInfoConst_user_app RO A string containing the name of
the application used to create the capture, or nil if there is no user_app string. */
-WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(CaptureInfoConst,user_app,wth->shb_hdr.shb_user_appl);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(CaptureInfoConst,user_app,wth->shb_hdr,OPT_SHB_USERAPPL);
/* WSLUA_ATTRIBUTE CaptureInfoConst_hosts RO A ip-to-hostname Lua table of two key-ed names: `ipv4_addresses` and `ipv6_addresses`.
The value of each of these names are themselves array tables, of key-ed tables, such that the inner table has a key