aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-07-14 16:01:57 -0700
committerGuy Harris <guy@alum.mit.edu>2016-07-14 23:02:39 +0000
commit1f8999bb96018446e48529e75e56bf17dd3c77cf (patch)
tree0103d875702fa1a7c64816e21e079d7ceee190c2 /epan/wslua
parent42e72d529cdbab62d52a26332985ecf28b997a87 (diff)
Redo the block options APIs.
A block can have zero or more instances of a given option. We distinguish between "one instance only" options, where a block can have zero or one instance, and "multiple instances allowed" options, where a block can have zero or more instances. For "one instance only" options: "add" routines add an instance if there isn't one already and fail if there is; "set" routines add an instance if there isn't one already and change the value of the existing instance if there is one; "set nth" routines fail; "get" routines return the value of the instance if there is one and fail if there isn't; "get nth" routines fail. For "multiple instances allowed" options: "add" routines add an instance; "set" routines fail; "set nth" routines set the value of the nth instance if there is one and fail otherwise; "get" routines fail; "get nth" routines get the value if the nth instance if there is one and fail otherwise. Rename "optionblock" to just "block"; it describes the contents of a block, including both mandatory items and options. Add some support for NRB options, including IPv4 and IPv6 option types. Change-Id: Iad184f668626c3d1498b2ed00c7f1672e4abf52e Reviewed-on: https://code.wireshark.org/review/16444 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/wslua')
-rw-r--r--epan/wslua/wslua.h39
-rw-r--r--epan/wslua/wslua_capture_info.c4
2 files changed, 38 insertions, 5 deletions
diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h
index 32f5bcb2ec..333c179687 100644
--- a/epan/wslua/wslua.h
+++ b/epan/wslua/wslua.h
@@ -557,8 +557,23 @@ extern int wslua_set__index(lua_State *L);
WSLUA_ATTRIBUTE_GET(C,name, { \
char* str; \
if ((obj->member) && (obj->member->len > 0)) { \
- wtap_optionblock_get_option_string(g_array_index(obj->member, wtap_optionblock_t, 0), option, &str); \
- lua_pushstring(L,str); /* this pushes nil if obj->member is null */ \
+ if (wtap_block_get_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, &str) == WTAP_OPTTYPE_SUCCESS) { \
+ lua_pushstring(L,str); /* this pushes nil if obj->member is null */ \
+ } \
+ } \
+ })
+
+/*
+ * XXX - we need to support Lua programs getting instances of a "multiple
+ * allowed" option other than the first option.
+ */
+#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(C,name,member,option) \
+ WSLUA_ATTRIBUTE_GET(C,name, { \
+ char* str; \
+ if ((obj->member) && (obj->member->len > 0)) { \
+ if (wtap_block_get_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, &str) == WTAP_OPTTYPE_SUCCESS) { \
+ lua_pushstring(L,str); /* this pushes nil if obj->member is null */ \
+ } \
} \
})
@@ -620,7 +635,25 @@ extern int wslua_set__index(lua_State *L);
return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
} \
if ((obj->member) && (obj->member->len > 0)) { \
- wtap_optionblock_set_option_string(g_array_index(obj->member, wtap_optionblock_t, 0), option, s, strlen(s)); \
+ wtap_block_set_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, s, strlen(s)); \
+ } \
+ g_free(s); \
+ return 0; \
+ } \
+ /* silly little trick so we can add a semicolon after this macro */ \
+ typedef void __dummy##C##_set_##field
+
+#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; \
+ 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 ); \
+ } \
+ if ((obj->member) && (obj->member->len > 0)) { \
+ wtap_block_set_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, s, strlen(s)); \
} \
g_free(s); \
return 0; \
diff --git a/epan/wslua/wslua_capture_info.c b/epan/wslua/wslua_capture_info.c
index e0293dad0b..433604770e 100644
--- a/epan/wslua/wslua_capture_info.c
+++ b/epan/wslua/wslua_capture_info.c
@@ -119,8 +119,8 @@ 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_OPT_BLOCK_STRING_GETTER(CaptureInfo,comment,wth->shb_hdrs,OPT_COMMENT);
-WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(CaptureInfo,comment,wth->shb_hdrs,OPT_COMMENT);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(CaptureInfo,comment,wth->shb_hdrs,OPT_COMMENT);
+WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(CaptureInfo,comment,wth->shb_hdrs,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. */