Wireshark-dev: [Wireshark-dev] Lua dll is outdated in windows binaries
From: Balint Reczey <Balint.Reczey@xxxxxxxxxxxx>
Date: Thu, 27 Dec 2007 16:09:00 +0100
Hi,

The attached patch makes TCP reassembly usable from Lua dissectors.
Could someone commit it?

Regards,
Balint
Index: epan/wslua/wslua.h
===================================================================
--- epan/wslua/wslua.h	(revision 23950)
+++ epan/wslua/wslua.h	(working copy)
@@ -342,7 +342,7 @@
 
 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);
Index: epan/wslua/init_wslua.c
===================================================================
--- epan/wslua/init_wslua.c	(revision 23950)
+++ epan/wslua/init_wslua.c	(working copy)
@@ -50,7 +50,8 @@
     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 @@
         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 @@
     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) {
Index: epan/wslua/wslua_proto.c
===================================================================
--- epan/wslua/wslua_proto.c	(revision 23950)
+++ epan/wslua/wslua_proto.c	(working copy)
@@ -1010,7 +1010,7 @@
     
     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 @@
         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 {