diff options
author | Guy Harris <guy@alum.mit.edu> | 2009-06-05 22:42:47 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2009-06-05 22:42:47 +0000 |
commit | cf91fdf16b2d961024ea062503ce5fb91af28186 (patch) | |
tree | 2654abe47f378933a5d325856a7b3f877338dd19 /epan/wslua/wslua_listener.c | |
parent | f84499059642f102c7272e72f74d7a986f51b520 (diff) |
Have tap listeners specify whether the "packet" routine requires
a protocol tree;
the column values.
This includes stats-tree listeners.
Have the routines to build the packet list, and to retap packets, honor
those requirements. This means that cf_retap_packets() no longer needs
an argument to specify whether to construct the column values or not, so
get rid of that argument.
This also means that there's no need for a tap to have a fake filter
to ensure that the protocol tree will be built, so don't set up a fake
"frame" filter.
While we're at it, clean up some cases where "no filter" was represented
as a null string rather than a null pointer.
Have a routine to return an indication of the number of tap listeners
with filters; use that rather than the global num_tap_filters.
Clean up some indentation and some gboolean vs. gint items.
svn path=/trunk/; revision=28645
Diffstat (limited to 'epan/wslua/wslua_listener.c')
-rw-r--r-- | epan/wslua/wslua_listener.c | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/epan/wslua/wslua_listener.c b/epan/wslua/wslua_listener.c index 22548849b4..f281f42204 100644 --- a/epan/wslua/wslua_listener.c +++ b/epan/wslua/wslua_listener.c @@ -44,10 +44,11 @@ int tap_packet_cb_error_handler(lua_State* L) { static gchar* last_error = NULL; static int repeated = 0; static int next = 2; - const gchar* where = (lua_pinfo) ? - ep_strdup_printf("Lua: on packet %i Error During execution of Listener Packet Callback",lua_pinfo->fd->num) : - ep_strdup_printf("Lua: Error During execution of Listener Packet Callback") ; - + const gchar* where = (lua_pinfo) ? + + ep_strdup_printf("Lua: on packet %i Error During execution of Listener Packet Callback",lua_pinfo->fd->num) : + ep_strdup_printf("Lua: Error During execution of Listener Packet Callback") ; + /* show the error the 1st, 3rd, 5th, 9th, 17th, 33th... time it appears to avoid window flooding */ /* XXX the last series of identical errors won't be shown (the user however gets at least one message) */ @@ -81,7 +82,7 @@ int tap_packet_cb_error_handler(lua_State* L) { int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const void *data) { Listener tap = tapdata; int retval = 0; - + if (tap->packet_ref == LUA_NOREF) return 0; lua_settop(tap->L,0); @@ -92,22 +93,22 @@ int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const push_Pinfo(tap->L, pinfo); push_Tvb(tap->L, edt->tvb); - if (tap->extractor) { - tap->extractor(tap->L,data); - } else { - lua_pushnil(tap->L); - } - + if (tap->extractor) { + tap->extractor(tap->L,data); + } else { + lua_pushnil(tap->L); + } + lua_pinfo = pinfo; lua_tvb = edt->tvb; lua_tree = g_malloc(sizeof(struct _wslua_treeitem)); - lua_tree->tree = edt->tree; - lua_tree->item = NULL; - lua_tree->expired = FALSE; + lua_tree->tree = edt->tree; + lua_tree->item = NULL; + lua_tree->expired = FALSE; switch ( lua_pcall(tap->L,3,1,1) ) { case 0: - retval = luaL_optint(tap->L,-1,1); + retval = luaL_optint(tap->L,-1,1); break; case LUA_ERRRUN: break; @@ -190,18 +191,18 @@ void lua_tap_draw(void *tapdata) { } WSLUA_CONSTRUCTOR Listener_new(lua_State* L) { - /* Creates a new Listener listener */ + /* Creates a new Listener listener */ #define WSLUA_OPTARG_Listener_new_TAP 1 /* The name of this tap */ #define WSLUA_OPTARG_Listener_new_FILTER 2 /* A filter that when matches the tap.packet function gets called (use nil to be called for every packet) */ const gchar* tap_type = luaL_optstring(L,WSLUA_OPTARG_Listener_new_TAP,"frame"); const gchar* filter = luaL_optstring(L,WSLUA_OPTARG_Listener_new_FILTER,NULL); - Listener tap; + Listener tap; GString* error; tap = g_malloc(sizeof(struct _wslua_tap)); - tap->name = g_strdup(tap_type); + tap->name = g_strdup(tap_type); tap->filter = filter ? g_strdup(filter) : NULL; tap->extractor = wslua_get_tap_extractor(tap_type); tap->L = L; @@ -209,13 +210,20 @@ WSLUA_CONSTRUCTOR Listener_new(lua_State* L) { tap->draw_ref = LUA_NOREF; tap->init_ref = LUA_NOREF; - error = register_tap_listener(tap_type, tap, tap->filter, lua_tap_reset, lua_tap_packet, lua_tap_draw); + /* + * XXX - do all Lua taps require the protocol tree? If not, it might + * be useful to have a way to indicate whether any do. + * + * XXX - do any Lua taps require the columns? If so, we either need + * to request them for this tap, or do so if any Lua taps require them. + */ + error = register_tap_listener(tap_type, tap, tap->filter, TL_REQUIRES_PROTO_TREE, lua_tap_reset, lua_tap_packet, lua_tap_draw); if (error) { g_free(tap->filter); g_free(tap->name); g_free(tap); - /* WSLUA_ERROR(new_tap,"tap registration error"); */ + /* WSLUA_ERROR(new_tap,"tap registration error"); */ luaL_error(L,"Error while registering tap:\n%s",error->str); g_string_free(error,TRUE); /* XXX LEAK? */ } @@ -225,7 +233,7 @@ WSLUA_CONSTRUCTOR Listener_new(lua_State* L) { } WSLUA_METHOD Listener_remove(lua_State* L) { - /* Removes a tap listener */ + /* Removes a tap listener */ Listener tap = checkListener(L,1); if (!tap) return 0; @@ -250,19 +258,19 @@ WSLUA_METAMETHOD Listener_tostring(lua_State* L) { static int Listener_newindex(lua_State* L) { - /* WSLUA_ATTRIBUTE Listener_packet WO A function that will be called once every packet matches the Listener listener filter. - - function tap.packet(pinfo,tvb,userdata) ... end - */ - /* WSLUA_ATTRIBUTE Listener_draw WO A function that will be called once every few seconds to redraw the gui objects - in tshark this funtion is called oly at the very end of the capture file. - - function tap.draw(userdata) ... end - */ - /* WSLUA_ATTRIBUTE Listener_reset WO A function that will be called at the end of the capture run. - - function tap.reset(userdata) ... end - */ + /* WSLUA_ATTRIBUTE Listener_packet WO A function that will be called once every packet matches the Listener listener filter. + + function tap.packet(pinfo,tvb,userdata) ... end + */ + /* WSLUA_ATTRIBUTE Listener_draw WO A function that will be called once every few seconds to redraw the gui objects + in tshark this funtion is called oly at the very end of the capture file. + + function tap.draw(userdata) ... end + */ + /* WSLUA_ATTRIBUTE Listener_reset WO A function that will be called at the end of the capture run. + + function tap.reset(userdata) ... end + */ Listener tap = shiftListener(L,1); const gchar* index = lua_shiftstring(L,1); int* refp = NULL; @@ -305,8 +313,8 @@ static const luaL_reg Listener_meta[] = { }; int Listener_register(lua_State* L) { - wslua_set_tap_enums(L); + wslua_set_tap_enums(L); WSLUA_REGISTER_CLASS(Listener); - return 1; + return 1; } |