aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua
diff options
context:
space:
mode:
authorRado Radoulov <rad0x6f@gmail.com>2017-04-27 13:06:24 -0400
committerPeter Wu <peter@lekensteyn.nl>2017-05-05 08:38:40 +0000
commitae8b18d6183538a4ffd5d18588be1b5e1a058206 (patch)
treee9b30127d9dfa9ac55d87fc1eb0cf4edcba89ffc /epan/wslua
parentce8863c6efcee54655b7856002430bd1716a7776 (diff)
New Lua function TreeItem:referenced(ProtoField | Dissector).
This function returns TRUE/FALSE depending whether the specified ProtoField/Dissector needs to be dissected. By using this function in conjunction with the TreeItem.visible attribute, Lua dissectors can be significantly sped up by making less C interop calls which are relatively slow in terms of dissection especially when using sub-protocols where the dissection of an entire protocol can be skipped. Added tests for TreeItem:referenced to protofield.lua Change-Id: I44feacb91a2a5b0e3c28c0ccd8d6b04cccd67261 Reviewed-on: https://code.wireshark.org/review/21387 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'epan/wslua')
-rw-r--r--epan/wslua/wslua_tree.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/epan/wslua/wslua_tree.c b/epan/wslua/wslua_tree.c
index bb78a19af8..09392d8f12 100644
--- a/epan/wslua/wslua_tree.c
+++ b/epan/wslua/wslua_tree.c
@@ -866,6 +866,37 @@ WSLUA_METHOD TreeItem_set_len(lua_State *L) {
WSLUA_RETURN(1); /* The same TreeItem. */
}
+WSLUA_METHOD TreeItem_referenced(lua_State *L) {
+ /* Checks if a ProtoField or Dissector is referenced by a filter/tap/UI.
+
+ If this function returns FALSE, it means that the field (or dissector) does not need to be dissected
+ and can be safely skipped. By skipping a field rather than dissecting it, the dissector will
+ 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
+ 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 ProtoField or a Dissector. The Dissector form is
+ usefull when you need to decide whether to call a sub-dissector.
+
+ @since 2.4
+ */
+#define WSLUA_ARG_TreeItem_referenced_PROTOFIELD 2 /* The ProtoField or Dissector to check if referenced. */
+ TreeItem ti = checkTreeItem(L, 1);
+ if (!ti) return 0;
+ ProtoField f = shiftProtoField(L, WSLUA_ARG_TreeItem_referenced_PROTOFIELD);
+ if (f) {
+ lua_pushboolean(L, proto_field_is_referenced(ti->tree, f->hfid));
+ }
+ else {
+ Dissector d = checkDissector(L, WSLUA_ARG_TreeItem_referenced_PROTOFIELD);
+ if (!d) return 0;
+ lua_pushboolean(L, proto_field_is_referenced(ti->tree, dissector_handle_get_protocol_index(d)));
+ }
+ WSLUA_RETURN(1); /* A boolean indicating if the ProtoField/Dissector is referenced */
+}
+
WSLUA_METAMETHOD TreeItem__tostring(lua_State* L) {
/* Returns string debug information about the `TreeItem`.
@@ -921,6 +952,7 @@ WSLUA_METHODS TreeItem_methods[] = {
WSLUA_CLASS_FNREG(TreeItem,set_generated),
WSLUA_CLASS_FNREG(TreeItem,set_hidden),
WSLUA_CLASS_FNREG(TreeItem,set_len),
+ WSLUA_CLASS_FNREG(TreeItem,referenced),
{ NULL, NULL }
};