From Balint Reczey (bug 2146):

Make it possible to write Lua dissectors that use TCP reassembly.

svn path=/trunk/; revision=24026
This commit is contained in:
Stig Bjørlykke 2008-01-07 21:24:23 +00:00
parent 485ba80ea9
commit 8959e6f766
3 changed files with 17 additions and 6 deletions

View File

@ -50,7 +50,8 @@ static int wslua_not_register_menu(lua_State* LS) {
return 0;
}
void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
int consumed_bytes = tvb->length;
lua_pinfo = pinfo;
lua_tvb = tvb;
@ -80,12 +81,20 @@ void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
push_Pinfo(L,pinfo);
push_TreeItem(L,lua_tree);
if ( lua_pcall(L,3,0,0) ) {
if ( lua_pcall(L,3,1,0) ) {
const gchar* error = lua_tostring(L,-1);
proto_item* pi = proto_tree_add_text(tree,tvb,0,0,"Lua Error: %s",error);
expert_add_info_format(pinfo, pi, PI_DEBUG, PI_ERROR ,"Lua Error");
} else {
/* if the Lua dissector reported the consumed bytes, pass it to our caller */
if (lua_isnumber(L, -1)) {
consumed_bytes = lua_tonumber(L, -1);
lua_pop(L, 1); /* pop returned value */
}
}
} else {
proto_item* pi = proto_tree_add_text(tree,tvb,0,0,"Lua Error: did not find the %s dissector"
" in the dissectors table",pinfo->current_proto);
@ -102,6 +111,8 @@ void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
lua_tree = NULL;
lua_tvb = NULL;
return consumed_bytes;
}
static void iter_table_and_call(lua_State* LS, int env, const gchar* table_name, lua_CFunction error_handler) {

View File

@ -342,7 +342,7 @@ extern lua_State* wslua_state(void);
extern gboolean wslua_optbool(lua_State* L, int n, gboolean def);
extern const gchar* lua_shiftstring(lua_State* L,int idx);
extern void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree);
extern int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree);
extern void proto_register_lua(void);
extern GString* lua_register_all_taps(void);

View File

@ -1010,7 +1010,7 @@ WSLUA_FUNCTION wslua_register_postdissector(lua_State* L) {
if(!proto->is_postdissector) {
if (! proto->handle) {
proto->handle = create_dissector_handle(dissect_lua, proto->hfid);
proto->handle = new_create_dissector_handle(dissect_lua, proto->hfid);
}
register_postdissector(proto->handle);
@ -1049,9 +1049,9 @@ static int Proto_set_dissector(lua_State* L) {
lua_replace(L, 2);
lua_settable(L,1);
proto->handle = create_dissector_handle(dissect_lua, proto->hfid);
proto->handle = new_create_dissector_handle(dissect_lua, proto->hfid);
register_dissector(loname, dissect_lua, proto->hfid);
new_register_dissector(loname, dissect_lua, proto->hfid);
return 0;
} else {