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_listener.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_listener.c')
-rw-r--r-- | epan/wslua/wslua_listener.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/epan/wslua/wslua_listener.c b/epan/wslua/wslua_listener.c index ec4d838db8..d504f52e9d 100644 --- a/epan/wslua/wslua_listener.c +++ b/epan/wslua/wslua_listener.c @@ -230,6 +230,35 @@ WSLUA_CONSTRUCTOR Listener_new(lua_State* L) { WSLUA_RETURN(1); /* The newly created Listener listener object */ } +/* Allow dissector key names to be sorted alphabetically */ +static gint +compare_dissector_key_name(gconstpointer dissector_a, gconstpointer dissector_b) +{ + return strcmp((const char*)dissector_a, (const char*)dissector_b); +} + +WSLUA_CONSTRUCTOR Listener_list (lua_State *L) { + /* Gets a Lua array table of all registered Listener tap names. + NOTE: this is an expensive operation, and should only be used for troubleshooting. */ + GList* list = get_tap_names(); + GList* elist = NULL; + int i = 1; + + if (!list) return luaL_error(L,"Cannot retrieve tap name list"); + + list = g_list_sort(list, (GCompareFunc)compare_dissector_key_name); + elist = g_list_first(list); + + lua_newtable(L); + for (i=1; elist; i++, elist = g_list_next(elist)) { + lua_pushstring(L,(const char *) elist->data); + lua_rawseti(L,1,i); + } + + g_list_free(list); + WSLUA_RETURN(1); /* The array table of registered tap names */ +} + WSLUA_METHOD Listener_remove(lua_State* L) { /* Removes a tap listener */ Listener tap = checkListener(L,1); @@ -292,6 +321,7 @@ WSLUA_ATTRIBUTES Listener_attributes[] = { WSLUA_METHODS Listener_methods[] = { WSLUA_CLASS_FNREG(Listener,new), WSLUA_CLASS_FNREG(Listener,remove), + WSLUA_CLASS_FNREG(Listener,list), { NULL, NULL } }; |