diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2006-10-17 18:20:44 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2006-10-17 18:20:44 +0000 |
commit | b8ef88a6e224192c3d19310e859d655377c6ae1c (patch) | |
tree | 1ee746243482ff3fe184e88beb6b55dbdf219cbe /epan | |
parent | 482ded17c639d2722a9d6dbaba622cde358eae3e (diff) |
Several changes:
- do not #include a c code file in wslua_register.c compile a separate boject
- add the console and evaluate windows
- add some useful vars to the lua environment
- some cleanup
- add the dtd generator code (currently disabled)
svn path=/trunk/; revision=19579
Diffstat (limited to 'epan')
-rw-r--r-- | epan/wslua/Makefile.am | 14 | ||||
-rw-r--r-- | epan/wslua/Makefile.nmake | 11 | ||||
-rw-r--r-- | epan/wslua/console.lua | 60 | ||||
-rw-r--r-- | epan/wslua/dtd_gen.lua | 336 | ||||
-rwxr-xr-x | epan/wslua/make-doc.pl | 40 | ||||
-rw-r--r-- | epan/wslua/make-taps.pl | 24 | ||||
-rw-r--r-- | epan/wslua/template-init.lua | 29 | ||||
-rw-r--r-- | epan/wslua/wslua.h | 17 | ||||
-rw-r--r-- | epan/wslua/wslua_field.c | 2 | ||||
-rw-r--r-- | epan/wslua/wslua_gui.c | 10 | ||||
-rw-r--r-- | epan/wslua/wslua_listener.c | 32 | ||||
-rw-r--r-- | epan/wslua/wslua_util.c | 2 |
12 files changed, 502 insertions, 75 deletions
diff --git a/epan/wslua/Makefile.am b/epan/wslua/Makefile.am index ab002ef2d5..3daff8718a 100644 --- a/epan/wslua/Makefile.am +++ b/epan/wslua/Makefile.am @@ -38,6 +38,7 @@ wslua_modules = \ libwslua_la_SOURCES = \ $(wslua_modules) \ + taps_wslua.c \ register_wslua.c \ init_wslua.c \ wslua.h @@ -45,11 +46,14 @@ libwslua_la_SOURCES = \ libwslua_la_LIBADD = @LUA_LIBS@ BUILT_SOURCES = \ - taps.c-inc \ + taps_wslua.c \ register_wslua.c \ declare_wslua.h -pkgdata_DATA = init.lua +pkgdata_DATA = \ + init.lua \ + console.lua \ + dtd_gen.lua CLEANFILES = \ *~ @@ -86,10 +90,10 @@ taps_used = \ taps: $(taps_used) touch taps -taps.c-inc: make-taps.pl taps - $(PERL) $(srcdir)/make-taps.pl taps taps.c-inc taps.txt +taps_wslua.c: make-taps.pl taps + $(PERL) $(srcdir)/make-taps.pl taps taps_wslua.c taps.txt -taps.txt: taps.c-inc +taps.txt: taps_wslua.c wslua.h: declare_wslua.h diff --git a/epan/wslua/Makefile.nmake b/epan/wslua/Makefile.nmake index dc650ff97c..21d571f81a 100644 --- a/epan/wslua/Makefile.nmake +++ b/epan/wslua/Makefile.nmake @@ -28,6 +28,7 @@ MODULES = \ OBJECTS= \ init_wslua.obj \ register_wslua.obj \ + taps_wslua.obj \ wslua_dumper.obj \ wslua_field.obj \ wslua_gui.obj \ @@ -42,7 +43,7 @@ wslua.lib : $(OBJECTS) init.lua link /lib /NODEFAULTLIB /out:wslua.lib $(OBJECTS) clean: - rm -f $(OBJECTS) wslua.lib $(PDB_FILE) init.lua taps.c-inc declare_wslua.h register_wslua.c taps.txt + rm -f $(OBJECTS) wslua.lib $(PDB_FILE) init.lua taps_wslua.c declare_wslua.h register_wslua.c taps.txt init_wslua.c: declare_wslua.h @@ -59,12 +60,10 @@ TAPS_USED = \ taps: $(TAPS_USED) touch taps -taps.c-inc: make-taps.pl taps - $(PERL) make-taps.pl taps taps.c-inc taps.txt +taps_wslua.c: make-taps.pl taps + $(PERL) make-taps.pl taps taps_wslua.c taps.txt -wslua_listener.c: taps.c-inc - -taps.txt: taps.c-inc +taps.txt: taps_wslua.c register_wslua.c: declare_wslua.h diff --git a/epan/wslua/console.lua b/epan/wslua/console.lua new file mode 100644 index 0000000000..b85994878c --- /dev/null +++ b/epan/wslua/console.lua @@ -0,0 +1,60 @@ +-- A console to execute commands in lua +if (gui_enabled()) then + local function evaluate_lua() + local w = TextWindow.new("Evaluate Lua") + w:set_editable(TRUE) + + function eval() + local text = string.gsub(w:get_text(),"%c*--%[%[.*--%]%]$","") + text = string.gsub(text,"^=","return ") + + local result = assert(loadstring(text))() + + if (result ~= nil) then + w:set(text .. '\n\n--[[ Result:\n' .. result .. '\n--]]') + else + w:set(text .. '\n\n--[[ Evaluated --]]') + end + end + + w:add_button("Evaluate",eval) + end + + local console_open = false + + local function run_console() + if console_open then return end + console_open = true + + local w = TextWindow.new("Console") + + local orig = { + critical = critical, + warn = warn, + message = message, + info = info, + debug = debug + } + + function critical(txt) w:append( "CRITICAL: " .. txt .. "\n") end + function warn(txt) w:append( "WARN: " .. txt .. "\n") end + function message(txt) w:append( "MESSAGE: " .. txt .. "\n") end + function info(txt) w:append( "INFO: " .. txt .. "\n") end + function debug(txt) w:append( "DEBUG: " .. txt .. "\n") end + + function at_close() + critical = orig.critical + warn = orig.warn + message = orig.message + info = orig.info + debug = orig.debug + + console_open = false + end + + w:set_atclose(at_close) + end + + register_menu("Evaluate Lua",evaluate_lua,MENU_TOOLS) + register_menu("Lua Console",run_console,MENU_TOOLS) +end
\ No newline at end of file diff --git a/epan/wslua/dtd_gen.lua b/epan/wslua/dtd_gen.lua new file mode 100644 index 0000000000..58629bf27e --- /dev/null +++ b/epan/wslua/dtd_gen.lua @@ -0,0 +1,336 @@ +-- dtd_gen.lua +-- +-- a DTD generator for wireshark +-- +-- (c) 2006 Luis E. Garcia Ontanon <luis.ontanon@gmail.com> +-- +-- $Id:$ +-- +-- Wireshark - Network traffic analyzer +-- By Gerald Combs <gerald@wireshark.org> +-- Copyright 1998 Gerald Combs +-- +-- This program is free software; you can redistribute it and/or +-- modify it under the terms of the GNU General Public License +-- as published by the Free Software Foundation; either version 2 +-- of the License, or (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +if gui_enabled() then + local xml_fld = Field.new("xml") + + local function dtd_generator() + local displayed = {} -- whether or not a dtd is already displayed + local dtds = {} -- the dtds + local changed = {} -- whether or not a dtd has been modified + local dtd -- the dtd being dealt with + local dtd_name -- its name + + -- we'll tap onto every frame that has xml + + local ws = {} -- the windows for each dtd + local w = TextWindow.new("DTD Generator") + + local function help() + local wh = TextWindow.new("DTD Generator Help") + -- XXX write help + wh:set('DTD Generator Help\n') + end + + local function get_dtd_from_xml(text,d,parent) + -- obtains dtd information from xml + -- text: xml to be parsed + -- d: the current dtd (if any) + -- parent: parent entity (if any) + + -- cleanup the text from useless chars + text = string.gsub(text ,"%s*<%s*","<"); + text = string.gsub(text ,"%s*>%s*",">"); + text = string.gsub(text ,"<%-%-(.-)%-%->"," "); + text = string.gsub(text ,"%s+"," "); + + while true do + -- find the first tag + local open_tag = string.match(text,"%b<>") + + if open_tag == nil then + -- no more tags, we're done + return true + end + + local name = string.match(open_tag,"[%w%d_-]+") + local this_ent = nil + + if d == nil then + -- there's no current dtd, this is entity is it + d = dtds[name] + + if d == nil then + d = {ents = {}, attrs = {}} + dtds[name] = d + end + + dtd = d + dtd_name = name + end + + this_ent = d[name] + + if this_ent == nil then + -- no entity by this name in this dtd, create it + this_ent = {ents = {}, attrs = {}} + d.ents[name] = this_ent + changed[dtd_name] = true + end + + if parent ~= nil then + -- add this entity to its parent + parent.ents[name] = 1 + changed[dtd_name] = true + end + + -- add the attrs to the entity + for att in string.gmatch(open_tag, "([%w%d_-]+)%s*=") do + if not this_ent.attrs[att] then + changed[dtd_name] = true + this_ent.attrs[att] = true + end + end + + if string.match(open_tag,"/>") then + -- this tag is "self closed" just remove it and continue + text = string.gsub(text,"%b<>","",1) + else + local close_tag_pat = "</%s*" .. name .. "%s*>" + if not string.match(text,close_tag_pat) then return false end + local span,left = string.match(text,"%b<>(.-)" .. close_tag_pat .. "(.*)") + + if span ~= nil then + -- recurse to find child entities + if not get_dtd_from_xml(span,d,this_ent) then + return false + end + end + + -- continue with what's left + text = left + end + end + + return true + end + + local function entity_tostring(name,entity_data) + -- name: the name of the entity + -- entity_data: a table containg the entity data + -- returns the dtd text for that entity + local text = '' + text = text .. '\t<!ELEMENT ' .. name .. ' (' --) + for e,j in pairs(entity_data.ents) do + text = text .. " " .. e .. ' |' + end + text = text .. " #PCDATA ) >\n" + + text = text .. "\t<!ATTLIST " .. name + for a,j in pairs(entity_data.attrs) do + text = text .. "\n\t\t" .. a .. ' CDTATA #IMPLIED' + end + text = text .. " >\n\n" + + text = string.gsub(text,"<!ATTLIST " .. name .. " >\n","") + + return text + end + + local function dtd_tostring(name,doctype) + local text = '<? wireshark:protocol proto_name="' .. name ..'" hierarchy="yes" ?>\n\n' + local root = doctype.ents[name] + doctype.ents[name] = nil + + text = text .. entity_tostring(name,root) + + for n,es in pairs(doctype.ents) do + text = text .. entity_tostring(n,es) + end + + doctype.ents[name] = root + + return text + end + + + local function element_body(name,text) + -- get the entity's children from dtd text + -- name: the name of the element + -- text: the list of children + text = string.gsub(text,"[%s%?%*%#%+%(%)]","") + text = string.gsub(text,"$","|") + text = string.gsub(text, + "^(.-)|", + function(s) + if dtd.ents[name] == nil then + dtd.ents[name] = {ents={},attrs={}} + end + + dtd.ents[name].ents[s] = true + return "" + end + ) + return '' + end + + local function attlist_body(name,text) + -- get the entity's attributes from dtd text + -- name: the name of the element + -- text: the list of attributes + text = string.gsub(text,"([%w%d_-]+) [A-Z]+ #[A-Z]+", + function(s) + dtd.atts[s] = true + return "" + end + ) + return '' + end + + local function dtd_body(buff) + -- get the dtd's entities from dtd text + -- buff: the dtd text + + local old_buff = buff + + buff = string.gsub(buff,"<!ELEMENT ([%w%d_-]+) (%b())>%s*",element_body) + buff = string.gsub(buff,"<!ATTLIST ([%w%d_-]+) (.-)>%s*",attlist_body) + end + + local function load_dtd(filename) + local dtd_filename = USER_DIR .. "/dtds/" .. filename + local buff = '' + local wireshark_info + + dtd_name = nil + dtd = nil + + for line in io.lines(dtd_filename) do + buff = buff .. line + end + + buff = string.gsub(buff ,"%s*<%!%s*","<!"); + buff = string.gsub(buff ,"%s*>%s*",">"); + buff = string.gsub(buff ,"<!%-%-(.-)%-%->"," "); + buff = string.gsub(buff ,"%s+"," "); + buff = string.gsub(buff ,"^%s+",""); + + + buff = string.gsub(buff,'(<%?%s*wireshark:protocol%s+.-%s*%?>)', + function(s) + wireshark_info = s + end + ) + + buff = string.gsub(buff,"^<!DOCTYPE ([%w%d_-]+) (%b[])%s*>", + function(name,body) + dtd = { ents = {}, attrs = {}} + dtd_name = name + + dtds[name] = dtd + + dtd_body(body) + + return "" + end + ) + + if not dtd then + dtd_body(buff) + end + + if wireshark_info then + dtd.wstag = wireshark_info + end + end + + local function load_dtds() + -- loads all existing dtds in the user directory + local dirname = persconffile_path("dtds") + local status, dir = pcall(Dir.open,dirname,".dtd") + + w:set('Loading DTDs from ' .. dirname .. ' \n') + + if not status then + w:append("Error: could not open the directory" .. dirname .. " , make sure it exists.\n") + return + end + + for dtd_filename in dir do + w:append("File:" .. dtd_filename .. "\n") + load_dtd(dtd_filename) + end + + end + + local function dtd_window(name) + return function() + local wd = TextWindow.new(name .. '.dtd') + wd:set(dtd_tostring(name,dtds[name])) + wd:set_editable() + + local function save() + local file = io.open(persconffile_path("dtds/") .. name .. ".dtd" ,"w") + file:write(wd:get_text()) + file:close() + end + + wd:add_button("Save",save) + end + end + + local function close() + if li ~= nil then + li:remove() + li = nil + end + end + + w:set_atclose(close) + + -- w:add_button("Help",help) + + load_dtds() + + local li = Listener.new("frame","xml") + + w:append('Running') + + function li.packet() + w:append('.') + local txt = xml_fld().range:string(); + get_dtd_from_xml(txt) + end + + function li.draw() + + for name,j in pairs(changed) do + w:append("\n" .. name .. " has changed\n") + if not displayed[name] then + w:add_button(name,dtd_window(name)) + displayed[name] = true + end + end + end + + retap_packets() + w:append(t2s(dtds)) + w:append('\n') + + end + + register_menu("DTD Generator",dtd_generator,MENU_TOOLS) +end diff --git a/epan/wslua/make-doc.pl b/epan/wslua/make-doc.pl index 47d2b1cf1f..8c9c477315 100755 --- a/epan/wslua/make-doc.pl +++ b/epan/wslua/make-doc.pl @@ -49,6 +49,37 @@ my $function; my @functions; my %template = %{{ + class_header => "<chapter id='%s'><title>%s</title>\n", + class_footer => "</chapter>\n", + class_desc => "<para>%s</para>\n", + class_constructors_header => "<section id='%s_constructors'><title>Constructors</title>\n", + class_constructors_footer => "</section>\n", + class_methods_header => "<section id='%s_methods'><title>Methods</title>\n", + class_methods_footer => "</section>\n", + class_attributes_header => "<section id='%s_attribs'><title>Attributes</title>\n", + class_attributes_footer => "</section>\n", + class_attr_header => "<section id='attrib_%s'><title>%s</title>\n", + class_attr_footer => "</section>\n", + class_attr_descr => "<para>%s<para>\n", + function_header => "<section id='fn_%s'><title>%s</title>\n", + function_descr => "<para>%s</para>\n", + function_footer => "</section>\n", + function_arg_header => "<section id='fn_arg_%s'><title>%s</title>\n", + function_arg_descr => "<para>%s</para>\n", + function_arg_footer => "</section>\n", + function_argerrors_header => "<section id='argerr_%s'><title>Errors</title><itemizedlist>\n", + function_argerror => "<listitem><para>%s</para></listitem>\n", + function_argerror_footer => "</section>\n", + function_returns_header => "<section id='ret_%s'><title>Returns</title>\n", + function_returns => "<para>%s</para>\n", + function_errors_header => "<section id='err_%s'><title>Errors</title><itemizedlist>\n", + function_error => "<listitem><para>%s</para></listitem>\n", + function_error_footer => "</section>\n", + non_method_functions_header => "<chapter id='non_method_functions'><title>Non Method Functions</title>\n", + non_method_functions_footer => "</chapter>\n", +}}; + +my %wiki_template = %{{ class_header => "= %s =\n", class_desc => "%s\n", class_constructors_header => "== %s constructors ==\n", @@ -83,7 +114,7 @@ my %metamethods = %{{ __unm => "-___", __concat => "__ .. __", __len => "#__", - __call => "()", + __call => "__()", __eq => "__ == __", __lt => "__ < __", __le => "__ <= __", @@ -270,7 +301,7 @@ while ( $file = shift) { for my $cname (sort keys %classes) { my $cl = $classes{$cname}; - printf D $template{class_header}, $cname; + printf D $template{class_header}, $cname, $cname; printf D $template{class_desc} , ${$cl}{descr} if ${$cl}{descr}; if ( $#{${$cl}{constructors}} >= 0) { @@ -315,6 +346,11 @@ while ( $file = shift) { printf D $template{class_attributes_footer}, $cname; } + + if (exists $template{class_footer}) { + printf D $template{class_footer}, $cname, $cname; + } + } if ($#functions >= 0) { diff --git a/epan/wslua/make-taps.pl b/epan/wslua/make-taps.pl index f287907ffb..fd340c0deb 100644 --- a/epan/wslua/make-taps.pl +++ b/epan/wslua/make-taps.pl @@ -124,7 +124,7 @@ sub dotap { $elems{$k} = $v; } - my $code = "void wslua_${tname}_to_table(lua_State* L, const void* p) { $sname* v = (void*)p; lua_newtable(L);\n"; + my $code = "static void wslua_${tname}_to_table(lua_State* L, const void* p) { $sname* v = (void*)p; lua_newtable(L);\n"; my $doc = "Tap: $tname\n"; for my $n (sort keys %elems) { @@ -155,6 +155,8 @@ print CFILE <<"HEADER"; /* This file is autogenerated from ./taps by ./make-taps.pl */ /* DO NOT EDIT! */ +#include "wslua.h" + HEADER print DOCFILE "\n"; @@ -170,7 +172,7 @@ while (<TAPSFILE>) { } print CFILE <<"TBLHDR"; -tappable_t tappables[] = { +static tappable_t tappables[] = { TBLHDR for my $tname (sort keys %functs) { @@ -184,7 +186,7 @@ print CFILE <<"TBLFTR"; {NULL,NULL} }; -void set_enums(lua_State* L) { +int wslua_set_tap_enums(lua_State* L) { TBLFTR @@ -199,7 +201,21 @@ ENUMELEM print CFILE "\tlua_settable(L,LUA_GLOBALSINDEX);\n"; } -print CFILE "};\n"; +print CFILE <<"TAIL"; + return 0; +}; + + +tap_extractor_t wslua_get_tap_extractor(const gchar* name) { + tappable_t* t; + for(t = tappables; t->name; t++ ) { + if (g_str_equal(t->name,name)) return t->extractor; + } + + return NULL; +} + +TAIL exit 0; diff --git a/epan/wslua/template-init.lua b/epan/wslua/template-init.lua index 0fe00b54cb..6eae877f97 100644 --- a/epan/wslua/template-init.lua +++ b/epan/wslua/template-init.lua @@ -25,7 +25,6 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -- If lua is to be completely disabled uncomment the following line. -- disable_lua = true; do return end; @@ -64,26 +63,10 @@ print = info -- %MENU_GROUPS% --- Console to execute commands in lua -function wslua_console() - local w = TextWindow.new("Lua Console") - w:set_editable(TRUE) - - function eval() - local text = string.gsub(w:get_text(),"%c*--%[%[.*--%]%]$","") - text = string.gsub(text,"^=","return ") - - local result = assert(loadstring(text))() - - if (result ~= nil) then - w:set(text .. '\n\n--[[ Result:\n' .. result .. '\n--]]') - else - w:set(text .. '\n\n--[[ Evaluated --]]') - end - end - - w:add_button("Evaluate",eval) -end - -register_menu("Lua Console",wslua_console,MENU_TOOLS) +-- other useful constants +GUI_ENABLED = gui_enabled() +DATA_DIR = datafile_path() +USER_DIR = persconffile_path() +dofile("console.lua") +--dofile("dtd_gen.lua") diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index 6490fa492e..b33e6a4422 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -121,6 +121,17 @@ struct _wslua_treeitem { proto_tree* tree; }; +typedef void (*tap_extractor_t)(lua_State*,const void*); + +struct _wslua_tap { + gchar* name; + gchar* filter; + tap_extractor_t extractor; + lua_State* L; + int packet_ref; + int draw_ref; + int init_ref; +}; #if GLIB_MAJOR_VERSION < 2 # define DIRECTORY_T DIR @@ -147,8 +158,6 @@ struct _wslua_dir { }; -typedef void (*tap_extractor_t)(lua_State*,const void*); - typedef struct { const char* name; tap_extractor_t extractor; } tappable_t; typedef struct {const gchar* str; enum ftenum id; } wslua_ft_types_t; @@ -328,5 +337,7 @@ extern void wslua_print_stack(char* s, lua_State* L); extern int wslua_init(lua_State* L); -extern int luaopen_libwireshark(lua_State* L); +extern tap_extractor_t wslua_get_tap_extractor(const gchar* name); +extern int wslua_set_tap_enums(lua_State* L); + #endif diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c index e96ccda28f..441a1816b1 100644 --- a/epan/wslua/wslua_field.c +++ b/epan/wslua/wslua_field.c @@ -408,7 +408,7 @@ WSLUA_METAMETHOD Field__call (lua_State* L) { WSLUA_RETURN(items_found); /* All the values of this field */ } -static int Field_tostring(lua_State* L) { +WSLUA_METAMETHOD Field_tostring(lua_State* L) { Field f = checkField(L,1); if ( !(f && *f) ) { diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c index 53b2fc0163..06ece4aac2 100644 --- a/epan/wslua/wslua_gui.c +++ b/epan/wslua/wslua_gui.c @@ -373,14 +373,14 @@ static int TextWindow__gc(lua_State* L) { return 1; } -WSLUA_METHOD TextWindow_set_editable(lua_State* L) { /* Set the function that will be called when the window closes */ -#define WSLUA_OPTARG_TextWindow_at_close_EDITABLE 2 /* A boolean flag, defaults to true */ +WSLUA_METHOD TextWindow_set_editable(lua_State* L) { /* Make this window editable */ +#define WSLUA_OPTARG_TextWindow_set_editable_EDITABLE 2 /* A boolean flag, defaults to true */ TextWindow tw = checkTextWindow(L,1); gboolean editable = luaL_optint(L,2,1); if (!tw) - WSLUA_ERROR(TextWindow_at_close,"cannot be called for something not a TextWindow"); + WSLUA_ERROR(TextWindow_set_editable,"cannot be called for something not a TextWindow"); if (ops->set_editable) ops->set_editable(tw,editable); @@ -433,7 +433,7 @@ WSLUA_METHOD TextWindow_add_button(lua_State* L) { wslua_bt_cb_t* cbd; if (!tw) - WSLUA_ERROR(TextWindow_at_close,"cannot be called for something not a TextWindow"); + WSLUA_ERROR(TextWindow_add_button,"cannot be called for something not a TextWindow"); if (! lua_isfunction(L,WSLUA_ARG_TextWindow_add_button_FUNCTION) ) WSLUA_ARG_ERROR(TextWindow_add_button,FUNCTION,"must be a function"); @@ -526,7 +526,7 @@ WSLUA_FUNCTION wslua_copy_to_clipboard(lua_State* L) { /* copy a string into the return 0; } -WSLUA_FUNCTION wslua_open_capture_file(lua_State* L) { +WSLUA_FUNCTION wslua_open_capture_file(lua_State* L) { /* open and display a capture file */ #define WSLUA_ARG_open_capture_file_FILENAME 1 /* The name of the file to be opened. */ #define WSLUA_ARG_open_capture_file_FILTER 2 /* A filter tgo be applied as the file gets opened. */ diff --git a/epan/wslua/wslua_listener.c b/epan/wslua/wslua_listener.c index e7b9dd73ff..9fd7fdd767 100644 --- a/epan/wslua/wslua_listener.c +++ b/epan/wslua/wslua_listener.c @@ -1,11 +1,13 @@ /* - * wslua_tap.c + * wslua_listener.c * * Wireshark's interface to the Lua Programming Language * + * Implementation of tap Listeners + * * (c) 2006, Luis E. Garcia Ontanon <luis.ontanon@gmail.com> * - * $Id: wslua_tap.c 18268 2006-05-31 17:38:42Z gerald $ + * $Id: wslua_listener.c 18268 2006-05-31 17:38:42Z gerald $ * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> @@ -28,33 +30,12 @@ #include "wslua.h" -/* generated file gets included */ -#include "taps.c-inc" - WSLUA_CLASS_DEFINE(Listener,NOP,NOP); /* A Listener, is called once for every packet that matches a certain filter or has a certain tap. It can read the tree, the packet's Tvb eventually the tapped data but it cannot add elements to the tree. */ -struct _wslua_tap { - gchar* name; - gchar* filter; - tap_extractor_t extractor; - lua_State* L; - int packet_ref; - int draw_ref; - int init_ref; -}; - -tap_extractor_t get_extractor(const gchar* name) { - tappable_t* t; - for(t = tappables; t->name; t++ ) { - if (g_str_equal(t->name,name)) return t->extractor; - } - - return NULL; -} int tap_packet_cb_error_handler(lua_State* L) { const gchar* error = lua_tostring(L,1); @@ -224,7 +205,7 @@ WSLUA_CONSTRUCTOR Listener_new(lua_State* L) { tap->name = g_strdup(tap_type); tap->filter = filter ? g_strdup(filter) : NULL; - tap->extractor = get_extractor(tap_type); + tap->extractor = wslua_get_tap_extractor(tap_type); tap->L = L; tap->packet_ref = LUA_NOREF; tap->draw_ref = LUA_NOREF; @@ -256,7 +237,7 @@ WSLUA_METHOD Listener_remove(lua_State* L) { return 0; } -static int Listener_tostring(lua_State* L) { +WSLUA_METAMETHOD Listener_tostring(lua_State* L) { Listener tap = checkListener(L,1); gchar* str; @@ -326,6 +307,7 @@ static const luaL_reg Listener_meta[] = { }; int Listener_register(lua_State* L) { + wslua_set_tap_enums(L); WSLUA_REGISTER_CLASS(Listener); return 1; } diff --git a/epan/wslua/wslua_util.c b/epan/wslua/wslua_util.c index 7b426fd150..620d7adb27 100644 --- a/epan/wslua/wslua_util.c +++ b/epan/wslua/wslua_util.c @@ -211,7 +211,7 @@ WSLUA_CONSTRUCTOR wslua_Dir_open(lua_State* L) { Dir dir; if (!dirname) WSLUA_ARG_ERROR(Dir_open,PATHNAME,"must be a string"); - if (!test_for_directory(dirname)) WSLUA_ARG_ERROR(Dir_open,PATHNAME,"must be a directory"); + if (!test_for_directory(dirname)) WSLUA_ARG_ERROR(Dir_open, PATHNAME, "must be a directory"); dir = g_malloc(sizeof(struct _wslua_dir)); dir->dir = OPENDIR_OP(dirname); |