diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2014-02-18 10:03:04 -0500 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2014-02-25 21:06:21 +0000 |
commit | 860747e1e78aefdaf31e77408ad590b9d759d1aa (patch) | |
tree | bcdb8aebc725be4f21e807d3345c0194a74ba28f /epan/wslua/wslua_field.c | |
parent | 907a8259862401af3fdc8ad1201e13c6abf677db (diff) | |
download | wireshark-860747e1e78aefdaf31e77408ad590b9d759d1aa.tar.gz |
Adds some Lua helper functions: some commonly used functions, and to help troubleshooting Lua scripts
There are some common things people need to do, such as convert to/from hex or get
the raw binary string in a ByteArray/Tvb/TvbRange. These have been added, as well
as some tests for them in the testsuites. Also, functions have been added to allow
a script to get all the available tap types and filter fields, since they are
not exactly what one can see in the Wireshark gui.
Change-Id: I92e5e4eae713bb90d79b0c024eaa4e55b99cc96b
Reviewed-on: https://code.wireshark.org/review/249
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'epan/wslua/wslua_field.c')
-rw-r--r-- | epan/wslua/wslua_field.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c index 335bb67f53..5fc5930ed7 100644 --- a/epan/wslua/wslua_field.c +++ b/epan/wslua/wslua_field.c @@ -495,6 +495,34 @@ WSLUA_CONSTRUCTOR Field_new(lua_State *L) { WSLUA_RETURN(1); /* The field extractor */ } +WSLUA_CONSTRUCTOR Field_list(lua_State *L) { + /* Gets a Lua array table of all registered field filter names. + NOTE: this is an expensive operation, and should only be used for troubleshooting. */ + void *cookie, *cookie2; + int i = -1; + int count = 0; + header_field_info *hfinfo = NULL; + + lua_newtable(L); + + for (i = proto_get_first_protocol(&cookie); i != -1; + i = proto_get_next_protocol(&cookie)) { + + for (hfinfo = proto_get_first_protocol_field(i, &cookie2); hfinfo != NULL; + hfinfo = proto_get_next_protocol_field(&cookie2)) { + + if (hfinfo->same_name_prev_id != -1) /* ignore duplicate names */ + continue; + + count++; + lua_pushstring(L,hfinfo->abbrev); + lua_rawseti(L,1,count); + } + } + + WSLUA_RETURN(1); /* The array table of field filter names */ +} + WSLUA_METAMETHOD Field__call (lua_State* L) { /* Obtain all values (see FieldInfo) for this field. */ Field f = checkField(L,1); @@ -549,6 +577,7 @@ static int Field__gc(lua_State* L _U_) { WSLUA_METHODS Field_methods[] = { WSLUA_CLASS_FNREG(Field,new), + WSLUA_CLASS_FNREG(Field,list), { NULL, NULL } }; |