diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2006-02-23 17:02:29 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2006-02-23 17:02:29 +0000 |
commit | 48551d9d85d93d6639ff763c7cdb6597e17b2b90 (patch) | |
tree | 5e804277e932b4f48e8df821efcf9a019119f6f7 /plugins/lua | |
parent | 060c5da8767d27903c0cd3c5a67b5c320acbfc62 (diff) |
- More "docOMMentation" of the API
- also supress Address__ge and Address_gt because re-reading the ref manual I noticed that they are suplerfluous (Lua assumes that a > b is equivalent to b < a, which in most cases (as this) it does)
- have elua_makedoc.pl hanlde docomments in more than one line and after the line where the entity s defined.
svn path=/trunk/; revision=17382
Diffstat (limited to 'plugins/lua')
-rw-r--r-- | plugins/lua/elua_dumper.c | 72 | ||||
-rw-r--r-- | plugins/lua/elua_makedoc.pl | 292 | ||||
-rw-r--r-- | plugins/lua/elua_pinfo.c | 166 | ||||
-rw-r--r-- | plugins/lua/elua_util.c | 68 |
4 files changed, 402 insertions, 196 deletions
diff --git a/plugins/lua/elua_dumper.c b/plugins/lua/elua_dumper.c index 3c92dd4bf2..2c8aa9e859 100644 --- a/plugins/lua/elua_dumper.c +++ b/plugins/lua/elua_dumper.c @@ -30,6 +30,9 @@ #include <math.h> ELUA_CLASS_DEFINE(PseudoHeader,NOP) +/* + A pseudoheader to be used to save captured frames. + */ enum lua_pseudoheader_type { PHDR_NONE, @@ -52,27 +55,42 @@ struct lua_pseudo_header { union wtap_pseudo_header* wph; }; -ELUA_CONSTRUCTOR PseudoHeader_none(lua_State* L) { /* creates a "no" pseudoheader */ +ELUA_CONSTRUCTOR PseudoHeader_none(lua_State* L) { + /* + Creates a "no" pseudoheader. + + */ PseudoHeader ph = g_malloc(sizeof(struct lua_pseudo_header)); ph->type = PHDR_NONE; ph->wph = NULL; pushPseudoHeader(L,ph); - ELUA_RETURN(1); /* A null pseudoheader */ + + ELUA_RETURN(1); + /* A null pseudoheader */ } -ELUA_CONSTRUCTOR PseudoHeader_eth(lua_State* L) { /* creates an ethernet pseudoheader */ +ELUA_CONSTRUCTOR PseudoHeader_eth(lua_State* L) { + /* + Creates an ethernet pseudoheader + */ + #define ELUA_OPTARG_PseudoHeader_eth_FCSLEN 1 /* the fcs lenght */ + PseudoHeader ph = g_malloc(sizeof(struct lua_pseudo_header)); ph->type = PHDR_ETH; ph->wph = g_malloc(sizeof(union wtap_pseudo_header)); ph->wph->eth.fcs_len = luaL_optint(L,1,-1); pushPseudoHeader(L,ph); + ELUA_RETURN(1); /* The ethernet pseudoheader */ } -ELUA_CONSTRUCTOR PseudoHeader_atm(lua_State* L) { /* Creates an ATM pseudoheader */ +ELUA_CONSTRUCTOR PseudoHeader_atm(lua_State* L) { + /* + Creates an ATM pseudoheader + */ #define ELUA_OPTARG_PseudoHeader_atm_AAL 1 /* AAL number */ #define ELUA_OPTARG_PseudoHeader_atm_VPI 2 /* VPI */ #define ELUA_OPTARG_PseudoHeader_atm_VCI 3 /* VCI */ @@ -93,10 +111,12 @@ ELUA_CONSTRUCTOR PseudoHeader_atm(lua_State* L) { /* Creates an ATM pseudoheader ph->wph->atm.aal5t_len = luaL_optint(L,ELUA_OPTARG_PseudoHeader_atm_AAL5LEN,0); pushPseudoHeader(L,ph); - ELUA_RETURN(1); /* The ATM pseudoheader */ + ELUA_RETURN(1); + /* The ATM pseudoheader */ } ELUA_CONSTRUCTOR PseudoHeader_mtp2(lua_State* L) { + /* Creates an MTP2 PseudoHeader */ #define ELUA_OPTARG_PseudoHeader_mtp2_SENT /* True if the packet is sent, False if received. */ #define ELUA_OPTARG_PseudoHeader_mtp2_ANNEXA /* True if annex A is used */ #define ELUA_OPTARG_PseudoHeader_mtp2_LINKNUM /* Link Number */ @@ -142,11 +162,14 @@ int PseudoHeader_register(lua_State* L) { ELUA_CLASS_DEFINE(Dumper,FAIL_ON_NULL("Dumper already closed")) - static GHashTable* dumper_encaps = NULL; #define DUMPER_ENCAP(d) GPOINTER_TO_INT(g_hash_table_lookup(dumper_encaps,d)) ELUA_CONSTRUCTOR Dumper_new(lua_State* L) { + /* + Creates a file to write packets. + Dumper:new_for_current() will probably be a better choice. + */ #define ELUA_ARG_Dumper_new_FILENAME 1 /* The name of the capture file to be created */ #define ELUA_OPTARG_Dumper_new_FILETYPE 3 /* The type of the file to be created */ #define ELUA_OPTARG_Dumper_new_ENCAP 3 /* The encapsulation to be used in the file to be created */ @@ -174,10 +197,12 @@ ELUA_CONSTRUCTOR Dumper_new(lua_State* L) { g_hash_table_insert(dumper_encaps,d,GINT_TO_POINTER(encap)); pushDumper(L,d); - ELUA_RETURN(1); /* The newly created Dumper object */ + ELUA_RETURN(1); + /* The newly created Dumper object */ } -ELUA_METHOD Dumper_close(lua_State* L) { /* close a dumper */ +ELUA_METHOD Dumper_close(lua_State* L) { + /* Closes a dumper */ Dumper* dp; int err; @@ -185,7 +210,7 @@ ELUA_METHOD Dumper_close(lua_State* L) { /* close a dumper */ dp = (Dumper*)luaL_checkudata(L, 1, "Dumper"); if (! *dp) - ELUA_ERROR(Dumper_close,"Dumper already closed"); + ELUA_ERROR(Dumper_close,"Cannot operate on a closed dumper"); g_hash_table_remove(dumper_encaps,*dp); @@ -200,7 +225,10 @@ ELUA_METHOD Dumper_close(lua_State* L) { /* close a dumper */ return 0; } -ELUA_METHOD Dumper_flush(lua_State* L) { /* writes all unsaved data of a dumper to the disk. */ +ELUA_METHOD Dumper_flush(lua_State* L) { + /* + Writes all unsaved data of a dumper to the disk. + */ Dumper d = checkDumper(L,1); if (!d) return 0; @@ -210,7 +238,11 @@ ELUA_METHOD Dumper_flush(lua_State* L) { /* writes all unsaved data of a dumper return 0; } -ELUA_METHOD Dumper_dump(lua_State* L) { /* Dumps an arbitrary packet. Dumper:dump_current() will be better used in most occasions. */ +ELUA_METHOD Dumper_dump(lua_State* L) { + /* + Dumps an arbitrary packet. + Note: Dumper:dump_current() will fit best in most cases. + */ #define ELUA_ARG_Dumper_dump_TIMESTAMP 2 /* The absolute timestamp the packet will have */ #define ELUA_ARG_Dumper_dump_PSEUDOHEADER 3 /* The Pseudoheader to use. */ #define ELUA_ARG_Dumper_dump_BYTEARRAY 4 /* the data to be saved */ @@ -227,7 +259,7 @@ ELUA_METHOD Dumper_dump(lua_State* L) { /* Dumps an arbitrary packet. Dumper:dum ts = luaL_checknumber(L,ELUA_ARG_Dumper_dump_TIMESTAMP); ph = checkPseudoHeader(L,ELUA_ARG_Dumper_dump_PSEUDOHEADER); - if (!ph) ELUA_ARG_ERROR(Dumper_dump,TIMESTAMP,"Need a PseudoHeader"); + if (!ph) ELUA_ARG_ERROR(Dumper_dump,TIMESTAMP,"need a PseudoHeader"); ba = checkByteArray(L,ELUA_ARG_Dumper_dump_BYTEARRAY); @@ -248,7 +280,10 @@ ELUA_METHOD Dumper_dump(lua_State* L) { /* Dumps an arbitrary packet. Dumper:dum } -ELUA_METHOD Dumper_new_for_current(lua_State* L) { /* Creates a capture file using the same encapsulation as the one of the cuurrent packet */ +ELUA_METHOD Dumper_new_for_current(lua_State* L) { + /* + Creates a capture file using the same encapsulation as the one of the cuurrent packet + */ #define ELUA_OPTARG_Dumper_new_for_current_FILETYPE 2 /* The file type. Defaults to pcap. */ Dumper d; const char* filename = luaL_checkstring(L,1); @@ -256,7 +291,8 @@ ELUA_METHOD Dumper_new_for_current(lua_State* L) { /* Creates a capture file usi int encap; int err = 0; - if (! lua_pinfo ) ELUA_ERROR(Dumper_new_for_current,"cannot be used outside a tap or a dissector"); + if (! lua_pinfo ) + ELUA_ERROR(Dumper_new_for_current,"cannot be used outside a tap or a dissector"); encap = lua_pinfo->fd->lnk_t; @@ -281,7 +317,10 @@ ELUA_METHOD Dumper_new_for_current(lua_State* L) { /* Creates a capture file usi } -ELUA_METHOD Dumper_dump_current(lua_State* L) { /* Dumps the current packet as it is. */ +ELUA_METHOD Dumper_dump_current(lua_State* L) { + /* + Dumps the current packet as it is. + */ Dumper d = checkDumper(L,1); struct wtap_pkthdr pkthdr; const guchar* data; @@ -310,10 +349,11 @@ ELUA_METHOD Dumper_dump_current(lua_State* L) { /* Dumps the current packet as i return 0; } -ELUA_METAMETHOD Dumper__gc(lua_State* L) { /* closes a dumper and releases the memory it uses */ +static int Dumper__gc(lua_State* L) { Dumper* dp; int err; + /* If we are Garbage Collected it means the Dumper is no longer usable. Close it */ luaL_checktype(L,1,LUA_TUSERDATA); dp = (Dumper*)luaL_checkudata(L, 1, "Dumper"); diff --git a/plugins/lua/elua_makedoc.pl b/plugins/lua/elua_makedoc.pl index 0d9f770bf8..2244bdba98 100644 --- a/plugins/lua/elua_makedoc.pl +++ b/plugins/lua/elua_makedoc.pl @@ -1,7 +1,9 @@ #!/usr/bin/perl # # elua_makedoc.pl -# Reference Manual Generator +# ELUA's Reference Manual Generator +# +# (c) 2006, Luis E. Garcia Onatnon <luis.ontanon@gmail.com> # # $Id$ # @@ -29,7 +31,16 @@ use strict; #use V2P; sub deb { -#warn $_[0] if $_[0] =~ /^>e/; +# warn $_[0]; +} + +sub gorolla { +# a gorilla stays to a chimp like ... stays to chomp +# but this one returns the shrugged string. + my $s = shift; + $s =~ s/^([\n]|\s)*//ms; + $s =~ s/([\n]|\s)*$//ms; + $s; } my $class; @@ -37,12 +48,14 @@ my %classes; my $function; my @functions; - my %template = %{{ class_header => "= %s =\n", class_desc => "%s\n", class_constructors_header => "== %s constructors ==\n", class_methods_header => "== %s methods ==\n", + class_attributes_header => "== %s Attributes ==\n", + class_attr_header => "=== %s ===\n", + class_attr_descr => "%s\n", function_header => "=== %s ===\n", function_descr => "%s\n", function_arg_header => "==== %s ====\n", @@ -54,61 +67,160 @@ my %template = %{{ function_errors_header => "==== errors ====\n", function_errors => " * %s\n", non_method_functions_header => "= Non method functions =\n", - }}; -my @control = ( - -[ 'ELUA_CLASS_DEFINE\050\s*([A-Z][a-zA-Z]+)\s*,[^\051]*\051\s*(/\*(.*?)\*/)?', - sub { - deb ">c=$1=$2=$3=$4=$5=$6=$7=\n"; - $class = { name => $1, descr=> $3, constructors => [], methods => [] }; - $classes{$1} = $class; - }], +my %metamethods = %{{ + __tostring => "tostring(__)", + __index => "__[]", + __newindex => "__[] => ", + __add => "__ + __", + __sub => "__ - __", + __mul => "__ * __", + __div => "__ / __", + __mod => "__ % __", + __pow => "__ ^ __", + __unm => "-___", + __concat => "__ .. __", + __len => "#__", + __call => "()", + __eq => "__ == __", + __lt => "__ < __", + __le => "__ <= __", +}}; -[ 'ELUA_FUNCTION\s+elua_([a-z_]+)[^\173]*\173\s*(/\*(.*?)\*/)?', - sub { - deb ">f=$1=$2=$3=$4=$5=$6=$7=\n"; - $function = { returns => [], arglist => [], args => {}, name => $1, descr => $3, type => 'standalone' }; - push @functions, $function; - } ] , +# It's said that only perl can parse perl... my editor isn't perl... +# if unencoded this causes my editor's autoindent to bail out so I encoded in octal +# XXX: support \" within "" +my $QUOTED_RE = "\042\050\133^\042\135*\051\042"; + +my $TRAILING_COMMENT_RE = '((\s*|[\n\r]*)/\*(.*?)\*/)?'; + +my @control = +( +# This will be scanned in order trying to match the re if it matches +# the body will be executed immediatelly after. + + [ 'ELUA_CLASS_DEFINE\050\s*([A-Z][a-zA-Z]+)\s*,.*?\051' . $TRAILING_COMMENT_RE, +sub { + deb ">c=$1=$2=$3=$4=$5=$6=$7=\n"; + $class = { + name => $1, + descr=> gorolla($4), + constructors => [], + methods => [], + metamethods => [], + attributes => [] + }; + $classes{$1} = $class; +}], -[ 'ELUA_CONSTRUCTOR\s+([A-Za-z]+)_([a-z_]+)[^\173]*\173\s*(/\*(.*?)\*/)?', +[ 'ELUA_FUNCTION\s+elua_([a-z_]+)[^\173]*\173' . $TRAILING_COMMENT_RE, +sub { + deb ">f=$1=$2=$3=$4=$5=$6=$7=\n"; + $function = { + returns => [], + arglist => [], + args => {}, + name => $1, + descr => gorolla($4), + type => 'standalone' + }; + push @functions, $function; +} ] , + +[ 'ELUA_CONSTRUCTOR\s+([A-Za-z]+)_([a-z_]+).*?\173' . $TRAILING_COMMENT_RE, +sub { + deb ">cc=$1=$2=$3=$4=$5=$6=$7=\n"; + $function = { + returns => [], + arglist => [], + args => {}, + name => "$1.$2", + descr => gorolla($5), + type => 'constructor' + }; + push @{${$class}{constructors}}, $function; +} ] , + +[ 'ELUA_METHOD\s+([A-Za-z]+)_([a-z_]+)[^\173]*\173' . $TRAILING_COMMENT_RE, sub { - deb ">cc=$1=$2=$3=$4=$5=$6=$7=\n"; - $function = { returns => [], arglist => [], args => {}, name => "$1.$2", descr => $4, type => 'constructor' }; - push @{${$class}{constructors}}, $function; + deb ">cm=$1=$2=$3=$4=$5=$6=$7=\n"; + $function = { + returns => [], + arglist => [], + args => {}, + name => "$1:$2", + descr => gorolla($5), + type => 'method' + }; + push @{${$class}{methods}}, $function; } ] , -[ 'ELUA_METHOD\s+([A-Za-z]+)_([a-z_]+)[^\173]*\173\s*(/\*(.*?)\*/)?', +[ 'ELUA_METAMETHOD\s+([A-Za-z]+)(__[a-z]+)[^\173]*\173' . $TRAILING_COMMENT_RE, sub { deb ">cm=$1=$2=$3=$4=$5=$6=$7=\n"; - $function = { returns => [], arglist => [], args => {}, name => "$1:$2", descr => $4, type => 'method' }; - push @{${$class}{methods}}, $function; + my $name = $metamethods{$2}; + my ($c,$d) = ($1,$5); + $name =~ s/__/$c/g; + $function = { + returns => [], + arglist => [], + args => {}, + name => $name, + descr => gorolla($d), + type => 'metamethod' + }; + push @{${$class}{metamethods}}, $function; } ] , -[ '#define ELUA_(OPT)?ARG_([a-z_]+)_([A-Z0-9]+)\s+\d+\s*(/\*(.*?)\*/)?', +[ '#define ELUA_(OPT)?ARG_([a-z_]+)_([A-Z0-9]+)\s+\d+' . $TRAILING_COMMENT_RE, +sub { + deb ">a=$1=$2=$3=$4=$5=$6=$7=\n"; + push @{${$function}{arglist}} , $3; + ${${$function}{args}}{$3} = {descr=>$6} +} ], + +[ '#define ELUA_(OPT)?ARG_([A-Za-z]+)_([a-z_]+)_([A-Z0-9]+)\s+\d+' . $TRAILING_COMMENT_RE, +sub { + deb ">ca=$1=$2=$3=$4=$5=$6=$7=\n"; + push @{${$function}{arglist}} , $4; + ${${$function}{args}}{$4} = {descr=>$7} +} ], + +[ '/\052\s+ELUA_ATTRIBUTE\s+([A-Za-z]+)_([a-z_]+)\s+([A-Z]*)\s*(.*?)\052/', sub { - deb ">a=$1=$2=$3=$4=$5=$6=$7=\n"; - push @{${$function}{arglist}} , $3; - ${${$function}{args}}{$3} = {descr=>$5} + deb ">at=$1=$2=$3=$4=$5=$6=$7=\n"; + push @{${$class}{attributes}}, { name => $2, descr => gorolla($4), mode=>$3 }; } ], -[ '#define ELUA_(OPT)?ARG_([A-Za-z]+)_([a-z_]+)_([A-Z0-9]+)\s+\d+\s*(/\*(.*?)\*/)?', +[ '/\052\s+ELUA_MOREARGS\s+([A-Za-z_]+)\s+(.*?)\052/', sub { - deb ">ca=$1=$2=$3=$4=$5=$6=$7=\n"; - push @{${$function}{arglist}} , $4; - ${${$function}{args}}{$4} = {descr=>$6} + deb ">ma=$1=$2=$3=$4=$5=$6=$7=\n"; + push @{${$function}{arglist}} , "..."; + ${${$function}{args}}{"..."} = {descr=>gorolla($2)} } ], -[ 'ELUA_(FINAL_)?RETURN\050\s*.*?\s*\051\s*;\s*(/\*(.*?)\*/)?', +[ 'ELUA_(FINAL_)?RETURN\050\s*.*?\s*\051\s*;' . $TRAILING_COMMENT_RE, +sub { + deb ">fr=$1=$2=$3=$4=$5=$6=$7=\n"; + push @{${$function}{returns}} , gorolla($4) if $4 ne ''; +} ], + +[ 'ELUA_ERROR\s*\050\s*(([A-Z][A-Za-z]+)_)?([a-z_]+),' . $QUOTED_RE , sub { - deb ">fr=$1=$2=$3=$4=$5=$6=$7=\n"; - push @{${$function}{returns}} , $3 if $3 ne ''; + deb ">e=$1=$2=$3=$4=$5=$6=$7=\n"; + my $errors; + unless (exists ${$function}{errors}) { + $errors = ${$function}{errors} = []; + } else { + $errors = ${$function}{errors}; + } + + push @{$errors}, gorolla($4); } ], -[ 'ELUA_(OPT)?ARG_ERROR\s*\050\s*(([A-Z][A-Za-z]+)_)?([a-z_]+)\s*,\s*([A-Z0-9]+)\s*,\s*"([^"]*)"', +[ 'ELUA_(OPT)?ARG_ERROR\s*\050\s*(([A-Z][A-Za-z]+)_)?([a-z_]+)\s*,\s*([A-Z0-9]+)\s*,\s*' . $QUOTED_RE, sub { deb ">ae=$1=$2=$3=$4=$5=$6=$7=\n"; my $errors; @@ -118,31 +230,21 @@ my @control = ( $errors = ${${${$function}{args}}{$5}}{errors}; } - push @{$errors}, $6; + push @{$errors}, gorolla($6); } ] , - [ 'ELUA_ERROR\s*\050\s*(([A-Z][A-Za-z]+)_)?([a-z_]+),"([^"]*)"', - sub { - deb ">e=$1=$2=$3=$4=$5=$6=$7=\n"; - my $errors; - unless (exists ${$function}{errors}) { - $errors = ${$function}{errors} = []; - } else { - $errors = ${$function}{errors}; - } - - push @{$errors}, $4; - - } ], - -#[ 'ELUA_ATTR_GET\s+([A-Za-z]+)_get_([a-z_]+)[^\173]*\173\s*(/\*(.*?)\*/)?', -# sub { } ] , -#[ 'ELUA_ATTR_SET\s+([A-Za-z]+)_set_([a-z_]+)[^\173]*\173\s*(/\*(.*?)\*/)?', -# sub { } ] , -#['(.*?\n)', -# sub { print "--->$1" } ], ); + +my $anymatch = '(^ThIsWiLlNeVeRmAtCh$'; +for (@control) { + $anymatch .= "|${$_}[0]"; +} +$anymatch .= ')'; + +# for each file given in the command line args my $file; while ( $file = shift) { + + next unless -f $file; my $docfile = $file; $docfile =~ s/\.c$/.pod/; @@ -151,41 +253,68 @@ while ( $file = shift) { open D, "> doc/$docfile"; my $b = ''; - LINE: while (<C>) { - $b .= $_; + $b .= $_ while (<C>); + + while ($b =~ /$anymatch/ms ) { + my $match = $1; +# print "\n-----\n$match\n-----\n"; for (@control) { my ($re,$f) = @{$_}; - while ( $b =~ s/$re//ms ) { - &{$f}(); - next LINE; + if ( $match =~ /$re/ms) { + &{$f}(); + $b =~ s/.*?$re//ms; + last; } } } for my $cname (sort keys %classes) { - my $class = $classes{$cname}; + my $cl = $classes{$cname}; printf D $template{class_header}, $cname; - printf D $template{class_desc} , ${$class}{descr} if ${$class}{descr}; + printf D $template{class_desc} , ${$cl}{descr} if ${$cl}{descr}; - if ( $#{${$class}{constructors}} >= 0) { + if ( $#{${$cl}{constructors}} >= 0) { printf D $template{class_constructors_header}, $cname; - for my $c (@{${$class}{constructors}}) { + for my $c (@{${$cl}{constructors}}) { function_descr($c); } printf D $template{class_constructors_footer}, $cname; } - if ( $#{${$class}{methods}} >= 0) { + if ( $#{${$cl}{methods}} >= 0) { printf D $template{class_methods_header}, $cname; - for my $m (@{${$class}{methods}}) { + for my $m (@{${$cl}{methods}}) { function_descr($m); } printf D $template{class_methods_footer}, $cname; } + + if ( $#{${$cl}{metamethods}} >= 0) { + printf D $template{class_metamethods_header}, $cname; + + for my $m (@{${$cl}{metamethods}}) { + function_descr($m,${$m}{name}); + } + + printf D $template{class_metamethods_footer}, $cname; + } + + if ( $#{${$cl}{attributes}} >= 0) { + printf D $template{class_attributes_header}, $cname; + + for my $a (@{${$cl}{attributes}}) { + printf D $template{class_attr_header}, ${$a}{name}; + printf D $template{class_attr_descr}, ${$a}{descr} if ${$a}{descr}; + printf D $template{class_attr_footer}, ${$a}{name}; + + } + + printf D $template{class_attributes_footer}, $cname; + } } if ($#functions >= 0) { @@ -206,17 +335,24 @@ while ( $file = shift) { sub function_descr { my $f = $_[0]; - my $arglist = ''; + my $label = $_[1]; - for (@{ ${$f}{arglist} }) { - my $a = $_; - $a =~ tr/A-Z/a-z/; - $arglist .= "$a, "; - } - - $arglist =~ s/, $//; + if (defined $label ) { + printf D $template{function_header}, $label; + } else { + my $arglist = ''; + + for (@{ ${$f}{arglist} }) { + my $a = $_; + $a =~ tr/A-Z/a-z/; + $arglist .= "$a, "; + } - printf D $template{function_header}, "${$f}{name}($arglist)"; + $arglist =~ s/, $//; + + printf D $template{function_header}, "${$f}{name}($arglist)"; + } + printf D $template{function_descr}, ${$f}{descr} if ${$f}{descr}; for my $argname (@{${$f}{arglist}}) { diff --git a/plugins/lua/elua_pinfo.c b/plugins/lua/elua_pinfo.c index 6d6df52440..a3fa1eb4d7 100644 --- a/plugins/lua/elua_pinfo.c +++ b/plugins/lua/elua_pinfo.c @@ -202,7 +202,7 @@ ELUA_METHODS Address_methods[] = { {0,0} }; -ELUA_METAMETHOD Address_tostring(lua_State* L) { +ELUA_METAMETHOD Address__tostring(lua_State* L) { Address addr = checkAddress(L,1); lua_pushstring(L,get_addr_name(addr)); @@ -221,33 +221,7 @@ static int Address_gc(lua_State* L) { return 0; } -ELUA_METAMETHOD Address_gt(lua_State* L) { - Address addr1 = checkAddress(L,1); - Address addr2 = checkAddress(L,2); - gboolean result = FALSE; - - if (CMP_ADDRESS(addr1, addr2) > 0) - result = TRUE; - - lua_pushboolean(L,result); - - return 1; -} - -ELUA_METAMETHOD Address_ge(lua_State* L) { - Address addr1 = checkAddress(L,1); - Address addr2 = checkAddress(L,2); - gboolean result = FALSE; - - if (CMP_ADDRESS(addr1, addr2) >= 0) - result = TRUE; - - lua_pushboolean(L,result); - - return 1; -} - -ELUA_METAMETHOD Address_eq(lua_State* L) { +ELUA_METAMETHOD Address__eq(lua_State* L) { /* compares two Addresses */ Address addr1 = checkAddress(L,1); Address addr2 = checkAddress(L,2); gboolean result = FALSE; @@ -260,7 +234,7 @@ ELUA_METAMETHOD Address_eq(lua_State* L) { return 1; } -ELUA_METAMETHOD Address_le(lua_State* L) { +ELUA_METAMETHOD Address__le(lua_State* L) { /* compares two Addresses */ Address addr1 = checkAddress(L,1); Address addr2 = checkAddress(L,2); gboolean result = FALSE; @@ -273,7 +247,7 @@ ELUA_METAMETHOD Address_le(lua_State* L) { return 1; } -ELUA_METAMETHOD Address_lt(lua_State* L) { +ELUA_METAMETHOD Address__lt(lua_State* L) { /* compares two Addresses */ Address addr1 = checkAddress(L,1); Address addr2 = checkAddress(L,2); gboolean result = FALSE; @@ -287,13 +261,11 @@ ELUA_METAMETHOD Address_lt(lua_State* L) { } ELUA_META Address_meta[] = { - {"__gc", Address_gc }, - {"__tostring", Address_tostring }, - {"__gt",Address_gt}, - {"__ge",Address_ge}, - {"__eq",Address_eq}, - {"__le",Address_le}, - {"__lt",Address_lt}, + {"__gc", Address__gc }, + {"__tostring", Address__tostring }, + {"__eq",Address__eq}, + {"__le",Address__le}, + {"__lt",Address__lt}, {0,0} }; @@ -304,7 +276,7 @@ int Address_register(lua_State *L) { } -ELUA_CLASS_DEFINE(Column,FAIL_ON_NULL("expired column")) +ELUA_CLASS_DEFINE(Column,FAIL_ON_NULL("expired column")) /* A Column in the packet list */ struct col_names_t { const gchar* name; @@ -383,7 +355,7 @@ static const gchar* col_id_to_name(gint id) { } -ELUA_METAMETHOD Column_tostring(lua_State *L) { +ELUA_METAMETHOD Column__tostring(lua_State *L) { Column c = checkColumn(L,1); const gchar* name; @@ -391,14 +363,14 @@ ELUA_METAMETHOD Column_tostring(lua_State *L) { return 0; } - /* XXX: can we format the column? */ + /* XXX: should return the column's text ! */ name = col_id_to_name(c->col); lua_pushstring(L,name ? name : "Unknown Column"); - return 1; + ELUA_RETURN(1); /* A string representing the column */ } -ELUA_METHOD Column_clear(lua_State *L) { +ELUA_METHOD Column_clear(lua_State *L) { /* Clears a Column */ Column c = checkColumn(L,1); if (!(c && c->cinfo)) return 0; @@ -409,11 +381,15 @@ ELUA_METHOD Column_clear(lua_State *L) { return 0; } -ELUA_METHOD Column_set(lua_State *L) { - Column c = checkColumn(L,1); - const gchar* s = luaL_checkstring(L,2); +ELUA_METHOD Column_set(lua_State *L) { /* Sets the text of a Column */ +#define ELUA_ARG_Column_set_TEXT 2 /* The text to which to set the Column */ + Column c = checkColumn(L,1); + const gchar* s = luaL_checkstring(L,ELUA_ARG_Column_set_TEXT); - if (!(c && c->cinfo && s)) return 0; + if (!(c && c->cinfo)) + return 0; + + if (!s) ELUA_ARG_ERROR(Column_set,TEXT,"must be a string"); if (check_col(c->cinfo, c->col)) col_set_str(c->cinfo, c->col, s); @@ -421,31 +397,40 @@ ELUA_METHOD Column_set(lua_State *L) { return 0; } -ELUA_METHOD Column_append(lua_State *L) { +ELUA_METHOD Column_append(lua_State *L) { /* Appends text to a Column */ +#define ELUA_ARG_Column_append_TEXT 2 /* The text to append to the Column */ Column c = checkColumn(L,1); - const gchar* s = luaL_checkstring(L,2); - - if (!(c && c->cinfo && s)) return 0; + const gchar* s = luaL_checkstring(L,ELUA_ARG_Column_append_TEXT); + if (!(c && c->cinfo)) + return 0; + + if (!s) ELUA_ARG_ERROR(Column_append,TEXT,"must be a string"); + + if (check_col(c->cinfo, c->col)) col_append_str(c->cinfo, c->col, s); return 0; } -ELUA_METHOD Column_preppend(lua_State *L) { +ELUA_METHOD Column_preppend(lua_State *L) { /* Prepends text to a Column */ +#define ELUA_ARG_Column_prepend_TEXT 2 /* The text to prepend to the Column */ Column c = checkColumn(L,1); - const gchar* s = luaL_checkstring(L,2); - - if (!(c && c->cinfo && s)) return 0; + const gchar* s = luaL_checkstring(L,ELUA_ARG_Column_prepend_TEXT); + if (!(c && c->cinfo)) + return 0; + + if (!s) ELUA_ARG_ERROR(Column_prepend,TEXT,"must be a string"); + if (check_col(c->cinfo, c->col)) col_prepend_fstr(c->cinfo, c->col, "%s",s); return 0; } -static const luaL_reg Column_methods[] = { +ELUA_METHODS Column_methods[] = { {"clear", Column_clear }, {"set", Column_set }, {"append", Column_append }, @@ -454,8 +439,8 @@ static const luaL_reg Column_methods[] = { }; -static const luaL_reg Column_meta[] = { - {"__tostring", Column_tostring }, +ELUA_META Column_meta[] = { + {"__tostring", Column__tostring }, {0,0} }; @@ -470,14 +455,16 @@ int Column_register(lua_State *L) { -ELUA_CLASS_DEFINE(Columns,FAIL_ON_NULL("expired columns")) +ELUA_CLASS_DEFINE(Columns,FAIL_ON_NULL("expired columns")) /* The Columns of the packet list. */ -static int Columns_tostring(lua_State *L) { +ELUA_METAMETHOD Columns__tostring(lua_State *L) { lua_pushstring(L,"Columns"); - return 1; + ELUA_RETURN(1); /* A string, mostly for debugging purposes */ } -ELUA_METAMETHOD Columns_newindex(lua_State *L) { +ELUA_METAMETHOD Columns__newindex(lua_State *L) { /* Sets the text of a specific column */ +#define ELUA_ARG_Columns__newindex_COLUMN 2 /* the name of the column to set */ +#define ELUA_ARG_Columns__newindex_TEXT 2 /* the text for the column */ Columns cols = checkColumns(L,1); const struct col_names_t* cn; const char* colname; @@ -485,9 +472,8 @@ ELUA_METAMETHOD Columns_newindex(lua_State *L) { if (!cols) return 0; - colname = luaL_checkstring(L,2); - text = luaL_checkstring(L,3); - + colname = luaL_checkstring(L,ELUA_ARG_Columns__newindex_COLUMN); + text = luaL_checkstring(L,ELUA_ARG_Columns__newindex_TEXT); for(cn = colnames; cn->name; cn++) { if( g_str_equal(cn->name,colname) ) { @@ -496,6 +482,8 @@ ELUA_METAMETHOD Columns_newindex(lua_State *L) { return 0; } } + + ELUA_ARG_ERROR(Columsn__newindex,COLUMN,"the column name must be a valid column"); return 0; } @@ -547,7 +535,7 @@ int Columns_register(lua_State *L) { } -ELUA_CLASS_DEFINE(Pinfo,FAIL_ON_NULL("expired pinfo")) +ELUA_CLASS_DEFINE(Pinfo,FAIL_ON_NULL("expired pinfo")) /* Packet information */ static int Pinfo_tostring(lua_State *L) { lua_pushstring(L,"a Pinfo"); return 1; } @@ -588,7 +576,6 @@ PINFO_GET_NUMBER(Pinfo_ptype,pinfo->ptype) PINFO_GET_NUMBER(Pinfo_src_port,pinfo->srcport) PINFO_GET_NUMBER(Pinfo_dst_port,pinfo->destport) - PINFO_GET_STRING(Pinfo_curr_proto,pinfo->current_proto) PINFO_GET_ADDRESS(Pinfo_net_src,net_src) @@ -720,28 +707,71 @@ typedef struct _pinfo_method_t { static const pinfo_method_t Pinfo_methods[] = { + + /* ELUA_ATTRIBUTE Pinfo_number RO The number of this packet in the current file */ {"number", Pinfo_number, pushnil_param, PARAM_NONE}, + + /* ELUA_ATTRIBUTE Pinfo_len RO The length of the frame */ {"len", Pinfo_len, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_caplen RO The captured length of the frame */ {"caplen", Pinfo_caplen, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_abs_ts RO When the packet was captured */ {"abs_ts",Pinfo_abs_ts, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_rel_ts RO Number of seconds passed since beginning of capture */ {"rel_ts",Pinfo_rel_ts, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_delta_ts RO Number of seconds passed since the last packet */ {"delta_ts",Pinfo_delta_ts, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_visited RO Whether this packet hass been already visited */ {"visited",Pinfo_visited, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_src RW Source Address of this Packet */ {"src", Pinfo_src, Pinfo_set_addr, PARAM_ADDR_SRC }, + + /* ELUA_ATTRIBUTE Pinfo_dst RW Destination Address of this Packet */ {"dst", Pinfo_dst, Pinfo_set_addr, PARAM_ADDR_DST }, + + /* ELUA_ATTRIBUTE Pinfo_dl_src RW Data Link Source Address of this Packet */ {"dl_src", Pinfo_dl_src, Pinfo_set_addr, PARAM_ADDR_DL_SRC }, + + /* ELUA_ATTRIBUTE Pinfo_dl_dst RW Data Link Destination Address of this Packet */ {"dl_dst", Pinfo_dl_dst, Pinfo_set_addr, PARAM_ADDR_DL_DST }, + + /* ELUA_ATTRIBUTE Pinfo_net_src RW Network Layer Source Address of this Packet */ {"net_src", Pinfo_net_src, Pinfo_set_addr, PARAM_ADDR_NET_SRC }, + + /* ELUA_ATTRIBUTE Pinfo_net_dst RW Network Layer Destination Address of this Packet */ {"net_dst", Pinfo_net_dst, Pinfo_set_addr, PARAM_ADDR_NET_DST }, + + /* ELUA_ATTRIBUTE Pinfo_ptype RW Type of Port of .src_port and .dst_port */ + {"port_type", Pinfo_ptype, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_src_port RW Source Port of this Packet */ {"src_port", Pinfo_src_port, Pinfo_set_int, PARAM_PORT_SRC }, + + /* ELUA_ATTRIBUTE Pinfo_dst_port RW Source Address of this Packet */ {"dst_port", Pinfo_dst_port, Pinfo_set_int, PARAM_PORT_SRC }, + + /* ELUA_ATTRIBUTE Pinfo_ipproto RO IP Protocol id */ {"ipproto", Pinfo_ipproto, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_circuit_id RO For circuit based protocols */ {"circuit_id", Pinfo_circuit_id, Pinfo_set_int, PARAM_CIRCUIT_ID }, - {"port_type", Pinfo_ptype, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_match RO Port/Data we are matching */ {"match", Pinfo_match, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_match RO Which Protocol are we dissecting */ {"curr_proto", Pinfo_curr_proto, pushnil_param, PARAM_NONE }, + + /* ELUA_ATTRIBUTE Pinfo_columns RO Accesss to the packet list columns */ {"cols", Pinfo_columns, pushnil_param, PARAM_NONE }, - {NULL,NULL,NULL,PARAM_NONE} + + {NULL,NULL,NULL,PARAM_NONE} }; diff --git a/plugins/lua/elua_util.c b/plugins/lua/elua_util.c index 4570cec400..b805f43ed1 100644 --- a/plugins/lua/elua_util.c +++ b/plugins/lua/elua_util.c @@ -40,37 +40,37 @@ ELUA_API const gchar* lua_shiftstring(lua_State* L, int i) { ELUA_FUNCTION elua_format_date(lua_State* LS) { /* Formats an absolute timestamp into a human readable date */ #define ELUA_ARG_format_date_TIMESTAMP 1 /* A timestamp value to convert. */ -lua_Number time = luaL_checknumber(LS,ELUA_ARG_format_date_TIMESTAMP); -nstime_t then; -gchar* str; + lua_Number time = luaL_checknumber(LS,ELUA_ARG_format_date_TIMESTAMP); + nstime_t then; + gchar* str; -then.secs = (guint32)floor(time); -then.nsecs = (guint32) ( (time-(double)(then.secs))*1000000000); -str = abs_time_to_str(&then); -lua_pushstring(LS,str); + then.secs = (guint32)floor(time); + then.nsecs = (guint32) ( (time-(double)(then.secs))*1000000000); + str = abs_time_to_str(&then); + lua_pushstring(LS,str); -ELUA_RETURN(1); /* a string with the formated date */ + ELUA_RETURN(1); /* a string with the formated date */ } ELUA_FUNCTION elua_format_time(lua_State* LS) { /* Formats an absolute timestamp in a human readable form */ #define ELUA_ARG_format_time_TIMESTAMP 1 /* a timestamp value to convert */ -lua_Number time = luaL_checknumber(LS,ELUA_ARG_format_time_TIMESTAMP); -nstime_t then; -gchar* str; + lua_Number time = luaL_checknumber(LS,ELUA_ARG_format_time_TIMESTAMP); + nstime_t then; + gchar* str; -then.secs = (guint32)floor(time); -then.nsecs = (guint32) ( (time-(double)(then.secs))*1000000000); -str = rel_time_to_str(&then); -lua_pushstring(LS,str); + then.secs = (guint32)floor(time); + then.nsecs = (guint32) ( (time-(double)(then.secs))*1000000000); + str = rel_time_to_str(&then); + lua_pushstring(LS,str); -ELUA_RETURN(1); /* a string with the formated time */ + ELUA_RETURN(1); /* a string with the formated time */ } ELUA_FUNCTION elua_report_failure(lua_State* LS) { /* reports a failure to the user */ #define ELUA_ARG_report_failure_TEXT 1 /* message */ -const gchar* s = luaL_checkstring(LS,ELUA_ARG_report_failure_TEXT); -report_failure("%s",s); -return 0; + const gchar* s = luaL_checkstring(LS,ELUA_ARG_report_failure_TEXT); + report_failure("%s",s); + return 0; } static int elua_log(lua_State* L, GLogLevelFlags log_level) { @@ -86,7 +86,7 @@ static int elua_log(lua_State* L, GLogLevelFlags log_level) { lua_call(L, 1, 1); s = lua_tostring(L, -1); /* get result */ if (s == NULL) - return luaL_error(L, "`tostring' must return a string to `print'"); + return luaL_error(L, "`tostring' must return a string"); if (i>1) g_string_append(str,"\t"); g_string_append(str,s); @@ -102,27 +102,27 @@ static int elua_log(lua_State* L, GLogLevelFlags log_level) { ELUA_FUNCTION elua_critical( lua_State* L ) { /* Will add a log entry with critical severity*/ /* ELUA_MOREARGS critical objects to be printed */ -elua_log(L,G_LOG_LEVEL_CRITICAL); -return 0; + elua_log(L,G_LOG_LEVEL_CRITICAL); + return 0; } ELUA_FUNCTION elua_warn( lua_State* L ) { /* Will add a log entry with warn severity */ -/* ELUA_MOREARGS critical objects to be printed */ -elua_log(L,G_LOG_LEVEL_WARNING); -return 0; +/* ELUA_MOREARGS warn objects to be printed */ + elua_log(L,G_LOG_LEVEL_WARNING); + return 0; } ELUA_FUNCTION elua_message( lua_State* L ) { /* Will add a log entry with message severity */ -/* ELUA_MOREARGS critical objects to be printed */ -elua_log(L,G_LOG_LEVEL_MESSAGE); -return 0; +/* ELUA_MOREARGS message objects to be printed */ + elua_log(L,G_LOG_LEVEL_MESSAGE); + return 0; } ELUA_FUNCTION elua_info( lua_State* L ) { /* Will add a log entry with info severity */ -/* ELUA_MOREARGS critical objects to be printed */ -elua_log(L,G_LOG_LEVEL_INFO); -return 0; +/* ELUA_MOREARGS info objects to be printed */ + elua_log(L,G_LOG_LEVEL_INFO); + return 0; } ELUA_FUNCTION elua_debug( lua_State* L ) { /* Will add a log entry with debug severity */ -/* ELUA_MOREARGS critical objects to be printed */ -elua_log(L,G_LOG_LEVEL_DEBUG); -return 0; +/* ELUA_MOREARGS debug objects to be printed */ + elua_log(L,G_LOG_LEVEL_DEBUG); + return 0; } |