forked from osmocom/wireshark
- 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
This commit is contained in:
parent
060c5da876
commit
48551d9d85
|
@ -30,6 +30,9 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
ELUA_CLASS_DEFINE(PseudoHeader,NOP)
|
ELUA_CLASS_DEFINE(PseudoHeader,NOP)
|
||||||
|
/*
|
||||||
|
A pseudoheader to be used to save captured frames.
|
||||||
|
*/
|
||||||
|
|
||||||
enum lua_pseudoheader_type {
|
enum lua_pseudoheader_type {
|
||||||
PHDR_NONE,
|
PHDR_NONE,
|
||||||
|
@ -52,27 +55,42 @@ struct lua_pseudo_header {
|
||||||
union wtap_pseudo_header* wph;
|
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));
|
PseudoHeader ph = g_malloc(sizeof(struct lua_pseudo_header));
|
||||||
ph->type = PHDR_NONE;
|
ph->type = PHDR_NONE;
|
||||||
ph->wph = NULL;
|
ph->wph = NULL;
|
||||||
|
|
||||||
pushPseudoHeader(L,ph);
|
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 */
|
#define ELUA_OPTARG_PseudoHeader_eth_FCSLEN 1 /* the fcs lenght */
|
||||||
|
|
||||||
PseudoHeader ph = g_malloc(sizeof(struct lua_pseudo_header));
|
PseudoHeader ph = g_malloc(sizeof(struct lua_pseudo_header));
|
||||||
ph->type = PHDR_ETH;
|
ph->type = PHDR_ETH;
|
||||||
ph->wph = g_malloc(sizeof(union wtap_pseudo_header));
|
ph->wph = g_malloc(sizeof(union wtap_pseudo_header));
|
||||||
ph->wph->eth.fcs_len = luaL_optint(L,1,-1);
|
ph->wph->eth.fcs_len = luaL_optint(L,1,-1);
|
||||||
|
|
||||||
pushPseudoHeader(L,ph);
|
pushPseudoHeader(L,ph);
|
||||||
|
|
||||||
ELUA_RETURN(1); /* The ethernet pseudoheader */
|
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_AAL 1 /* AAL number */
|
||||||
#define ELUA_OPTARG_PseudoHeader_atm_VPI 2 /* VPI */
|
#define ELUA_OPTARG_PseudoHeader_atm_VPI 2 /* VPI */
|
||||||
#define ELUA_OPTARG_PseudoHeader_atm_VCI 3 /* VCI */
|
#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);
|
ph->wph->atm.aal5t_len = luaL_optint(L,ELUA_OPTARG_PseudoHeader_atm_AAL5LEN,0);
|
||||||
|
|
||||||
pushPseudoHeader(L,ph);
|
pushPseudoHeader(L,ph);
|
||||||
ELUA_RETURN(1); /* The ATM pseudoheader */
|
ELUA_RETURN(1);
|
||||||
|
/* The ATM pseudoheader */
|
||||||
}
|
}
|
||||||
|
|
||||||
ELUA_CONSTRUCTOR PseudoHeader_mtp2(lua_State* L) {
|
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_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_ANNEXA /* True if annex A is used */
|
||||||
#define ELUA_OPTARG_PseudoHeader_mtp2_LINKNUM /* Link Number */
|
#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"))
|
ELUA_CLASS_DEFINE(Dumper,FAIL_ON_NULL("Dumper already closed"))
|
||||||
|
|
||||||
|
|
||||||
static GHashTable* dumper_encaps = NULL;
|
static GHashTable* dumper_encaps = NULL;
|
||||||
#define DUMPER_ENCAP(d) GPOINTER_TO_INT(g_hash_table_lookup(dumper_encaps,d))
|
#define DUMPER_ENCAP(d) GPOINTER_TO_INT(g_hash_table_lookup(dumper_encaps,d))
|
||||||
|
|
||||||
ELUA_CONSTRUCTOR Dumper_new(lua_State* L) {
|
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_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_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 */
|
#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));
|
g_hash_table_insert(dumper_encaps,d,GINT_TO_POINTER(encap));
|
||||||
|
|
||||||
pushDumper(L,d);
|
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;
|
Dumper* dp;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -185,7 +210,7 @@ ELUA_METHOD Dumper_close(lua_State* L) { /* close a dumper */
|
||||||
dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
|
dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
|
||||||
|
|
||||||
if (! *dp)
|
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);
|
g_hash_table_remove(dumper_encaps,*dp);
|
||||||
|
|
||||||
|
@ -200,7 +225,10 @@ ELUA_METHOD Dumper_close(lua_State* L) { /* close a dumper */
|
||||||
return 0;
|
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);
|
Dumper d = checkDumper(L,1);
|
||||||
|
|
||||||
if (!d) return 0;
|
if (!d) return 0;
|
||||||
|
@ -210,7 +238,11 @@ ELUA_METHOD Dumper_flush(lua_State* L) { /* writes all unsaved data of a dumper
|
||||||
return 0;
|
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_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_PSEUDOHEADER 3 /* The Pseudoheader to use. */
|
||||||
#define ELUA_ARG_Dumper_dump_BYTEARRAY 4 /* the data to be saved */
|
#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);
|
ts = luaL_checknumber(L,ELUA_ARG_Dumper_dump_TIMESTAMP);
|
||||||
ph = checkPseudoHeader(L,ELUA_ARG_Dumper_dump_PSEUDOHEADER);
|
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);
|
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. */
|
#define ELUA_OPTARG_Dumper_new_for_current_FILETYPE 2 /* The file type. Defaults to pcap. */
|
||||||
Dumper d;
|
Dumper d;
|
||||||
const char* filename = luaL_checkstring(L,1);
|
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 encap;
|
||||||
int err = 0;
|
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;
|
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);
|
Dumper d = checkDumper(L,1);
|
||||||
struct wtap_pkthdr pkthdr;
|
struct wtap_pkthdr pkthdr;
|
||||||
const guchar* data;
|
const guchar* data;
|
||||||
|
@ -310,10 +349,11 @@ ELUA_METHOD Dumper_dump_current(lua_State* L) { /* Dumps the current packet as i
|
||||||
return 0;
|
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;
|
Dumper* dp;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
/* If we are Garbage Collected it means the Dumper is no longer usable. Close it */
|
||||||
luaL_checktype(L,1,LUA_TUSERDATA);
|
luaL_checktype(L,1,LUA_TUSERDATA);
|
||||||
dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
|
dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# elua_makedoc.pl
|
# elua_makedoc.pl
|
||||||
# Reference Manual Generator
|
# ELUA's Reference Manual Generator
|
||||||
|
#
|
||||||
|
# (c) 2006, Luis E. Garcia Onatnon <luis.ontanon@gmail.com>
|
||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
#
|
#
|
||||||
|
@ -29,7 +31,16 @@ use strict;
|
||||||
#use V2P;
|
#use V2P;
|
||||||
|
|
||||||
sub deb {
|
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;
|
my $class;
|
||||||
|
@ -37,12 +48,14 @@ my %classes;
|
||||||
my $function;
|
my $function;
|
||||||
my @functions;
|
my @functions;
|
||||||
|
|
||||||
|
|
||||||
my %template = %{{
|
my %template = %{{
|
||||||
class_header => "= %s =\n",
|
class_header => "= %s =\n",
|
||||||
class_desc => "%s\n",
|
class_desc => "%s\n",
|
||||||
class_constructors_header => "== %s constructors ==\n",
|
class_constructors_header => "== %s constructors ==\n",
|
||||||
class_methods_header => "== %s methods ==\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_header => "=== %s ===\n",
|
||||||
function_descr => "%s\n",
|
function_descr => "%s\n",
|
||||||
function_arg_header => "==== %s ====\n",
|
function_arg_header => "==== %s ====\n",
|
||||||
|
@ -54,73 +67,147 @@ my %template = %{{
|
||||||
function_errors_header => "==== errors ====\n",
|
function_errors_header => "==== errors ====\n",
|
||||||
function_errors => " * %s\n",
|
function_errors => " * %s\n",
|
||||||
non_method_functions_header => "= Non method functions =\n",
|
non_method_functions_header => "= Non method functions =\n",
|
||||||
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
|
||||||
my @control = (
|
my %metamethods = %{{
|
||||||
|
__tostring => "tostring(__)",
|
||||||
|
__index => "__[]",
|
||||||
|
__newindex => "__[] => ",
|
||||||
|
__add => "__ + __",
|
||||||
|
__sub => "__ - __",
|
||||||
|
__mul => "__ * __",
|
||||||
|
__div => "__ / __",
|
||||||
|
__mod => "__ % __",
|
||||||
|
__pow => "__ ^ __",
|
||||||
|
__unm => "-___",
|
||||||
|
__concat => "__ .. __",
|
||||||
|
__len => "#__",
|
||||||
|
__call => "()",
|
||||||
|
__eq => "__ == __",
|
||||||
|
__lt => "__ < __",
|
||||||
|
__le => "__ <= __",
|
||||||
|
}};
|
||||||
|
|
||||||
[ 'ELUA_CLASS_DEFINE\050\s*([A-Z][a-zA-Z]+)\s*,[^\051]*\051\s*(/\*(.*?)\*/)?',
|
# 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 {
|
sub {
|
||||||
deb ">c=$1=$2=$3=$4=$5=$6=$7=\n";
|
deb ">c=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
$class = { name => $1, descr=> $3, constructors => [], methods => [] };
|
$class = {
|
||||||
|
name => $1,
|
||||||
|
descr=> gorolla($4),
|
||||||
|
constructors => [],
|
||||||
|
methods => [],
|
||||||
|
metamethods => [],
|
||||||
|
attributes => []
|
||||||
|
};
|
||||||
$classes{$1} = $class;
|
$classes{$1} = $class;
|
||||||
}],
|
}],
|
||||||
|
|
||||||
[ 'ELUA_FUNCTION\s+elua_([a-z_]+)[^\173]*\173\s*(/\*(.*?)\*/)?',
|
[ 'ELUA_FUNCTION\s+elua_([a-z_]+)[^\173]*\173' . $TRAILING_COMMENT_RE,
|
||||||
sub {
|
sub {
|
||||||
deb ">f=$1=$2=$3=$4=$5=$6=$7=\n";
|
deb ">f=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
$function = { returns => [], arglist => [], args => {}, name => $1, descr => $3, type => 'standalone' };
|
$function = {
|
||||||
|
returns => [],
|
||||||
|
arglist => [],
|
||||||
|
args => {},
|
||||||
|
name => $1,
|
||||||
|
descr => gorolla($4),
|
||||||
|
type => 'standalone'
|
||||||
|
};
|
||||||
push @functions, $function;
|
push @functions, $function;
|
||||||
} ] ,
|
} ] ,
|
||||||
|
|
||||||
[ 'ELUA_CONSTRUCTOR\s+([A-Za-z]+)_([a-z_]+)[^\173]*\173\s*(/\*(.*?)\*/)?',
|
[ 'ELUA_CONSTRUCTOR\s+([A-Za-z]+)_([a-z_]+).*?\173' . $TRAILING_COMMENT_RE,
|
||||||
sub {
|
sub {
|
||||||
deb ">cc=$1=$2=$3=$4=$5=$6=$7=\n";
|
deb ">cc=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
$function = { returns => [], arglist => [], args => {}, name => "$1.$2", descr => $4, type => 'constructor' };
|
$function = {
|
||||||
|
returns => [],
|
||||||
|
arglist => [],
|
||||||
|
args => {},
|
||||||
|
name => "$1.$2",
|
||||||
|
descr => gorolla($5),
|
||||||
|
type => 'constructor'
|
||||||
|
};
|
||||||
push @{${$class}{constructors}}, $function;
|
push @{${$class}{constructors}}, $function;
|
||||||
} ] ,
|
} ] ,
|
||||||
|
|
||||||
[ 'ELUA_METHOD\s+([A-Za-z]+)_([a-z_]+)[^\173]*\173\s*(/\*(.*?)\*/)?',
|
[ 'ELUA_METHOD\s+([A-Za-z]+)_([a-z_]+)[^\173]*\173' . $TRAILING_COMMENT_RE,
|
||||||
sub {
|
sub {
|
||||||
deb ">cm=$1=$2=$3=$4=$5=$6=$7=\n";
|
deb ">cm=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
$function = { returns => [], arglist => [], args => {}, name => "$1:$2", descr => $4, type => 'method' };
|
$function = {
|
||||||
|
returns => [],
|
||||||
|
arglist => [],
|
||||||
|
args => {},
|
||||||
|
name => "$1:$2",
|
||||||
|
descr => gorolla($5),
|
||||||
|
type => 'method'
|
||||||
|
};
|
||||||
push @{${$class}{methods}}, $function;
|
push @{${$class}{methods}}, $function;
|
||||||
} ] ,
|
} ] ,
|
||||||
|
|
||||||
[ '#define ELUA_(OPT)?ARG_([a-z_]+)_([A-Z0-9]+)\s+\d+\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";
|
||||||
|
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+' . $TRAILING_COMMENT_RE,
|
||||||
sub {
|
sub {
|
||||||
deb ">a=$1=$2=$3=$4=$5=$6=$7=\n";
|
deb ">a=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
push @{${$function}{arglist}} , $3;
|
push @{${$function}{arglist}} , $3;
|
||||||
${${$function}{args}}{$3} = {descr=>$5}
|
${${$function}{args}}{$3} = {descr=>$6}
|
||||||
} ],
|
} ],
|
||||||
|
|
||||||
[ '#define ELUA_(OPT)?ARG_([A-Za-z]+)_([a-z_]+)_([A-Z0-9]+)\s+\d+\s*(/\*(.*?)\*/)?',
|
[ '#define ELUA_(OPT)?ARG_([A-Za-z]+)_([a-z_]+)_([A-Z0-9]+)\s+\d+' . $TRAILING_COMMENT_RE,
|
||||||
sub {
|
sub {
|
||||||
deb ">ca=$1=$2=$3=$4=$5=$6=$7=\n";
|
deb ">ca=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
push @{${$function}{arglist}} , $4;
|
push @{${$function}{arglist}} , $4;
|
||||||
${${$function}{args}}{$4} = {descr=>$6}
|
${${$function}{args}}{$4} = {descr=>$7}
|
||||||
} ],
|
} ],
|
||||||
|
|
||||||
[ 'ELUA_(FINAL_)?RETURN\050\s*.*?\s*\051\s*;\s*(/\*(.*?)\*/)?',
|
[ '/\052\s+ELUA_ATTRIBUTE\s+([A-Za-z]+)_([a-z_]+)\s+([A-Z]*)\s*(.*?)\052/',
|
||||||
|
sub {
|
||||||
|
deb ">at=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
|
push @{${$class}{attributes}}, { name => $2, descr => gorolla($4), mode=>$3 };
|
||||||
|
} ],
|
||||||
|
|
||||||
|
[ '/\052\s+ELUA_MOREARGS\s+([A-Za-z_]+)\s+(.*?)\052/',
|
||||||
|
sub {
|
||||||
|
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*;' . $TRAILING_COMMENT_RE,
|
||||||
sub {
|
sub {
|
||||||
deb ">fr=$1=$2=$3=$4=$5=$6=$7=\n";
|
deb ">fr=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
push @{${$function}{returns}} , $3 if $3 ne '';
|
push @{${$function}{returns}} , gorolla($4) if $4 ne '';
|
||||||
} ],
|
} ],
|
||||||
|
|
||||||
[ 'ELUA_(OPT)?ARG_ERROR\s*\050\s*(([A-Z][A-Za-z]+)_)?([a-z_]+)\s*,\s*([A-Z0-9]+)\s*,\s*"([^"]*)"',
|
[ 'ELUA_ERROR\s*\050\s*(([A-Z][A-Za-z]+)_)?([a-z_]+),' . $QUOTED_RE ,
|
||||||
sub {
|
|
||||||
deb ">ae=$1=$2=$3=$4=$5=$6=$7=\n";
|
|
||||||
my $errors;
|
|
||||||
unless (exists ${${${$function}{args}}{$5}}{errors}) {
|
|
||||||
$errors = ${${${$function}{args}}{$5}}{errors} = [];
|
|
||||||
} else {
|
|
||||||
$errors = ${${${$function}{args}}{$5}}{errors};
|
|
||||||
}
|
|
||||||
|
|
||||||
push @{$errors}, $6;
|
|
||||||
} ] ,
|
|
||||||
[ 'ELUA_ERROR\s*\050\s*(([A-Z][A-Za-z]+)_)?([a-z_]+),"([^"]*)"',
|
|
||||||
sub {
|
sub {
|
||||||
deb ">e=$1=$2=$3=$4=$5=$6=$7=\n";
|
deb ">e=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
my $errors;
|
my $errors;
|
||||||
|
@ -130,20 +217,35 @@ my @control = (
|
||||||
$errors = ${$function}{errors};
|
$errors = ${$function}{errors};
|
||||||
}
|
}
|
||||||
|
|
||||||
push @{$errors}, $4;
|
push @{$errors}, gorolla($4);
|
||||||
|
|
||||||
} ],
|
} ],
|
||||||
|
|
||||||
#[ 'ELUA_ATTR_GET\s+([A-Za-z]+)_get_([a-z_]+)[^\173]*\173\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 { } ] ,
|
sub {
|
||||||
#[ 'ELUA_ATTR_SET\s+([A-Za-z]+)_set_([a-z_]+)[^\173]*\173\s*(/\*(.*?)\*/)?',
|
deb ">ae=$1=$2=$3=$4=$5=$6=$7=\n";
|
||||||
# sub { } ] ,
|
my $errors;
|
||||||
#['(.*?\n)',
|
unless (exists ${${${$function}{args}}{$5}}{errors}) {
|
||||||
# sub { print "--->$1" } ],
|
$errors = ${${${$function}{args}}{$5}}{errors} = [];
|
||||||
|
} else {
|
||||||
|
$errors = ${${${$function}{args}}{$5}}{errors};
|
||||||
|
}
|
||||||
|
|
||||||
|
push @{$errors}, gorolla($6);
|
||||||
|
} ] ,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my $anymatch = '(^ThIsWiLlNeVeRmAtCh$';
|
||||||
|
for (@control) {
|
||||||
|
$anymatch .= "|${$_}[0]";
|
||||||
|
}
|
||||||
|
$anymatch .= ')';
|
||||||
|
|
||||||
|
# for each file given in the command line args
|
||||||
my $file;
|
my $file;
|
||||||
while ( $file = shift) {
|
while ( $file = shift) {
|
||||||
|
|
||||||
|
next unless -f $file;
|
||||||
|
|
||||||
my $docfile = $file;
|
my $docfile = $file;
|
||||||
$docfile =~ s/\.c$/.pod/;
|
$docfile =~ s/\.c$/.pod/;
|
||||||
|
|
||||||
|
@ -151,41 +253,68 @@ while ( $file = shift) {
|
||||||
open D, "> doc/$docfile";
|
open D, "> doc/$docfile";
|
||||||
|
|
||||||
my $b = '';
|
my $b = '';
|
||||||
LINE: while (<C>) {
|
$b .= $_ while (<C>);
|
||||||
$b .= $_;
|
|
||||||
|
while ($b =~ /$anymatch/ms ) {
|
||||||
|
my $match = $1;
|
||||||
|
# print "\n-----\n$match\n-----\n";
|
||||||
for (@control) {
|
for (@control) {
|
||||||
my ($re,$f) = @{$_};
|
my ($re,$f) = @{$_};
|
||||||
while ( $b =~ s/$re//ms ) {
|
if ( $match =~ /$re/ms) {
|
||||||
&{$f}();
|
&{$f}();
|
||||||
next LINE;
|
$b =~ s/.*?$re//ms;
|
||||||
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for my $cname (sort keys %classes) {
|
for my $cname (sort keys %classes) {
|
||||||
my $class = $classes{$cname};
|
my $cl = $classes{$cname};
|
||||||
printf D $template{class_header}, $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;
|
printf D $template{class_constructors_header}, $cname;
|
||||||
|
|
||||||
for my $c (@{${$class}{constructors}}) {
|
for my $c (@{${$cl}{constructors}}) {
|
||||||
function_descr($c);
|
function_descr($c);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf D $template{class_constructors_footer}, $cname;
|
printf D $template{class_constructors_footer}, $cname;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $#{${$class}{methods}} >= 0) {
|
if ( $#{${$cl}{methods}} >= 0) {
|
||||||
printf D $template{class_methods_header}, $cname;
|
printf D $template{class_methods_header}, $cname;
|
||||||
|
|
||||||
for my $m (@{${$class}{methods}}) {
|
for my $m (@{${$cl}{methods}}) {
|
||||||
function_descr($m);
|
function_descr($m);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf D $template{class_methods_footer}, $cname;
|
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) {
|
if ($#functions >= 0) {
|
||||||
|
@ -206,6 +335,11 @@ while ( $file = shift) {
|
||||||
|
|
||||||
sub function_descr {
|
sub function_descr {
|
||||||
my $f = $_[0];
|
my $f = $_[0];
|
||||||
|
my $label = $_[1];
|
||||||
|
|
||||||
|
if (defined $label ) {
|
||||||
|
printf D $template{function_header}, $label;
|
||||||
|
} else {
|
||||||
my $arglist = '';
|
my $arglist = '';
|
||||||
|
|
||||||
for (@{ ${$f}{arglist} }) {
|
for (@{ ${$f}{arglist} }) {
|
||||||
|
@ -217,6 +351,8 @@ sub function_descr {
|
||||||
$arglist =~ s/, $//;
|
$arglist =~ s/, $//;
|
||||||
|
|
||||||
printf D $template{function_header}, "${$f}{name}($arglist)";
|
printf D $template{function_header}, "${$f}{name}($arglist)";
|
||||||
|
}
|
||||||
|
|
||||||
printf D $template{function_descr}, ${$f}{descr} if ${$f}{descr};
|
printf D $template{function_descr}, ${$f}{descr} if ${$f}{descr};
|
||||||
|
|
||||||
for my $argname (@{${$f}{arglist}}) {
|
for my $argname (@{${$f}{arglist}}) {
|
||||||
|
|
|
@ -202,7 +202,7 @@ ELUA_METHODS Address_methods[] = {
|
||||||
{0,0}
|
{0,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
ELUA_METAMETHOD Address_tostring(lua_State* L) {
|
ELUA_METAMETHOD Address__tostring(lua_State* L) {
|
||||||
Address addr = checkAddress(L,1);
|
Address addr = checkAddress(L,1);
|
||||||
|
|
||||||
lua_pushstring(L,get_addr_name(addr));
|
lua_pushstring(L,get_addr_name(addr));
|
||||||
|
@ -221,33 +221,7 @@ static int Address_gc(lua_State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ELUA_METAMETHOD Address_gt(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;
|
|
||||||
|
|
||||||
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) {
|
|
||||||
Address addr1 = checkAddress(L,1);
|
Address addr1 = checkAddress(L,1);
|
||||||
Address addr2 = checkAddress(L,2);
|
Address addr2 = checkAddress(L,2);
|
||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
|
@ -260,7 +234,7 @@ ELUA_METAMETHOD Address_eq(lua_State* L) {
|
||||||
return 1;
|
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 addr1 = checkAddress(L,1);
|
||||||
Address addr2 = checkAddress(L,2);
|
Address addr2 = checkAddress(L,2);
|
||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
|
@ -273,7 +247,7 @@ ELUA_METAMETHOD Address_le(lua_State* L) {
|
||||||
return 1;
|
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 addr1 = checkAddress(L,1);
|
||||||
Address addr2 = checkAddress(L,2);
|
Address addr2 = checkAddress(L,2);
|
||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
|
@ -287,13 +261,11 @@ ELUA_METAMETHOD Address_lt(lua_State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ELUA_META Address_meta[] = {
|
ELUA_META Address_meta[] = {
|
||||||
{"__gc", Address_gc },
|
{"__gc", Address__gc },
|
||||||
{"__tostring", Address_tostring },
|
{"__tostring", Address__tostring },
|
||||||
{"__gt",Address_gt},
|
{"__eq",Address__eq},
|
||||||
{"__ge",Address_ge},
|
{"__le",Address__le},
|
||||||
{"__eq",Address_eq},
|
{"__lt",Address__lt},
|
||||||
{"__le",Address_le},
|
|
||||||
{"__lt",Address_lt},
|
|
||||||
{0,0}
|
{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 {
|
struct col_names_t {
|
||||||
const gchar* name;
|
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);
|
Column c = checkColumn(L,1);
|
||||||
const gchar* name;
|
const gchar* name;
|
||||||
|
|
||||||
|
@ -391,14 +363,14 @@ ELUA_METAMETHOD Column_tostring(lua_State *L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: can we format the column? */
|
/* XXX: should return the column's text ! */
|
||||||
name = col_id_to_name(c->col);
|
name = col_id_to_name(c->col);
|
||||||
lua_pushstring(L,name ? name : "Unknown Column");
|
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);
|
Column c = checkColumn(L,1);
|
||||||
|
|
||||||
if (!(c && c->cinfo)) return 0;
|
if (!(c && c->cinfo)) return 0;
|
||||||
|
@ -409,11 +381,15 @@ ELUA_METHOD Column_clear(lua_State *L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ELUA_METHOD Column_set(lua_State *L) {
|
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);
|
Column c = checkColumn(L,1);
|
||||||
const gchar* s = luaL_checkstring(L,2);
|
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))
|
if (check_col(c->cinfo, c->col))
|
||||||
col_set_str(c->cinfo, c->col, s);
|
col_set_str(c->cinfo, c->col, s);
|
||||||
|
@ -421,11 +397,16 @@ ELUA_METHOD Column_set(lua_State *L) {
|
||||||
return 0;
|
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);
|
Column c = checkColumn(L,1);
|
||||||
const gchar* s = luaL_checkstring(L,2);
|
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 (!(c && c->cinfo && s)) return 0;
|
|
||||||
|
|
||||||
if (check_col(c->cinfo, c->col))
|
if (check_col(c->cinfo, c->col))
|
||||||
col_append_str(c->cinfo, c->col, s);
|
col_append_str(c->cinfo, c->col, s);
|
||||||
|
@ -433,11 +414,15 @@ ELUA_METHOD Column_append(lua_State *L) {
|
||||||
return 0;
|
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);
|
Column c = checkColumn(L,1);
|
||||||
const gchar* s = luaL_checkstring(L,2);
|
const gchar* s = luaL_checkstring(L,ELUA_ARG_Column_prepend_TEXT);
|
||||||
|
|
||||||
if (!(c && c->cinfo && s)) return 0;
|
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))
|
if (check_col(c->cinfo, c->col))
|
||||||
col_prepend_fstr(c->cinfo, c->col, "%s",s);
|
col_prepend_fstr(c->cinfo, c->col, "%s",s);
|
||||||
|
@ -445,7 +430,7 @@ ELUA_METHOD Column_preppend(lua_State *L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_reg Column_methods[] = {
|
ELUA_METHODS Column_methods[] = {
|
||||||
{"clear", Column_clear },
|
{"clear", Column_clear },
|
||||||
{"set", Column_set },
|
{"set", Column_set },
|
||||||
{"append", Column_append },
|
{"append", Column_append },
|
||||||
|
@ -454,8 +439,8 @@ static const luaL_reg Column_methods[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const luaL_reg Column_meta[] = {
|
ELUA_META Column_meta[] = {
|
||||||
{"__tostring", Column_tostring },
|
{"__tostring", Column__tostring },
|
||||||
{0,0}
|
{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");
|
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);
|
Columns cols = checkColumns(L,1);
|
||||||
const struct col_names_t* cn;
|
const struct col_names_t* cn;
|
||||||
const char* colname;
|
const char* colname;
|
||||||
|
@ -485,9 +472,8 @@ ELUA_METAMETHOD Columns_newindex(lua_State *L) {
|
||||||
|
|
||||||
if (!cols) return 0;
|
if (!cols) return 0;
|
||||||
|
|
||||||
colname = luaL_checkstring(L,2);
|
colname = luaL_checkstring(L,ELUA_ARG_Columns__newindex_COLUMN);
|
||||||
text = luaL_checkstring(L,3);
|
text = luaL_checkstring(L,ELUA_ARG_Columns__newindex_TEXT);
|
||||||
|
|
||||||
|
|
||||||
for(cn = colnames; cn->name; cn++) {
|
for(cn = colnames; cn->name; cn++) {
|
||||||
if( g_str_equal(cn->name,colname) ) {
|
if( g_str_equal(cn->name,colname) ) {
|
||||||
|
@ -497,6 +483,8 @@ ELUA_METAMETHOD Columns_newindex(lua_State *L) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ELUA_ARG_ERROR(Columsn__newindex,COLUMN,"the column name must be a valid column");
|
||||||
|
|
||||||
return 0;
|
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; }
|
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_src_port,pinfo->srcport)
|
||||||
PINFO_GET_NUMBER(Pinfo_dst_port,pinfo->destport)
|
PINFO_GET_NUMBER(Pinfo_dst_port,pinfo->destport)
|
||||||
|
|
||||||
|
|
||||||
PINFO_GET_STRING(Pinfo_curr_proto,pinfo->current_proto)
|
PINFO_GET_STRING(Pinfo_curr_proto,pinfo->current_proto)
|
||||||
|
|
||||||
PINFO_GET_ADDRESS(Pinfo_net_src,net_src)
|
PINFO_GET_ADDRESS(Pinfo_net_src,net_src)
|
||||||
|
@ -720,27 +707,70 @@ typedef struct _pinfo_method_t {
|
||||||
|
|
||||||
|
|
||||||
static const pinfo_method_t Pinfo_methods[] = {
|
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},
|
{"number", Pinfo_number, pushnil_param, PARAM_NONE},
|
||||||
|
|
||||||
|
/* ELUA_ATTRIBUTE Pinfo_len RO The length of the frame */
|
||||||
{"len", Pinfo_len, pushnil_param, PARAM_NONE },
|
{"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 },
|
{"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 },
|
{"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 },
|
{"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 },
|
{"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 },
|
{"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 },
|
{"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 },
|
{"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 },
|
{"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 },
|
{"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 },
|
{"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 },
|
{"net_dst", Pinfo_net_dst, Pinfo_set_addr, PARAM_ADDR_NET_DST },
|
||||||
{"src_port", Pinfo_src_port, Pinfo_set_int, PARAM_PORT_SRC },
|
|
||||||
{"dst_port", Pinfo_dst_port, Pinfo_set_int, PARAM_PORT_SRC },
|
/* ELUA_ATTRIBUTE Pinfo_ptype RW Type of Port of .src_port and .dst_port */
|
||||||
{"ipproto", Pinfo_ipproto, pushnil_param, PARAM_NONE },
|
|
||||||
{"circuit_id", Pinfo_circuit_id, Pinfo_set_int, PARAM_CIRCUIT_ID },
|
|
||||||
{"port_type", Pinfo_ptype, pushnil_param, PARAM_NONE },
|
{"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 },
|
||||||
|
|
||||||
|
/* ELUA_ATTRIBUTE Pinfo_match RO Port/Data we are matching */
|
||||||
{"match", Pinfo_match, pushnil_param, PARAM_NONE },
|
{"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 },
|
{"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 },
|
{"cols", Pinfo_columns, pushnil_param, PARAM_NONE },
|
||||||
|
|
||||||
{NULL,NULL,NULL,PARAM_NONE}
|
{NULL,NULL,NULL,PARAM_NONE}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ static int elua_log(lua_State* L, GLogLevelFlags log_level) {
|
||||||
lua_call(L, 1, 1);
|
lua_call(L, 1, 1);
|
||||||
s = lua_tostring(L, -1); /* get result */
|
s = lua_tostring(L, -1); /* get result */
|
||||||
if (s == NULL)
|
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");
|
if (i>1) g_string_append(str,"\t");
|
||||||
g_string_append(str,s);
|
g_string_append(str,s);
|
||||||
|
@ -106,22 +106,22 @@ elua_log(L,G_LOG_LEVEL_CRITICAL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ELUA_FUNCTION elua_warn( lua_State* L ) { /* Will add a log entry with warn severity */
|
ELUA_FUNCTION elua_warn( lua_State* L ) { /* Will add a log entry with warn severity */
|
||||||
/* ELUA_MOREARGS critical objects to be printed */
|
/* ELUA_MOREARGS warn objects to be printed */
|
||||||
elua_log(L,G_LOG_LEVEL_WARNING);
|
elua_log(L,G_LOG_LEVEL_WARNING);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ELUA_FUNCTION elua_message( lua_State* L ) { /* Will add a log entry with message severity */
|
ELUA_FUNCTION elua_message( lua_State* L ) { /* Will add a log entry with message severity */
|
||||||
/* ELUA_MOREARGS critical objects to be printed */
|
/* ELUA_MOREARGS message objects to be printed */
|
||||||
elua_log(L,G_LOG_LEVEL_MESSAGE);
|
elua_log(L,G_LOG_LEVEL_MESSAGE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ELUA_FUNCTION elua_info( lua_State* L ) { /* Will add a log entry with info severity */
|
ELUA_FUNCTION elua_info( lua_State* L ) { /* Will add a log entry with info severity */
|
||||||
/* ELUA_MOREARGS critical objects to be printed */
|
/* ELUA_MOREARGS info objects to be printed */
|
||||||
elua_log(L,G_LOG_LEVEL_INFO);
|
elua_log(L,G_LOG_LEVEL_INFO);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ELUA_FUNCTION elua_debug( lua_State* L ) { /* Will add a log entry with debug severity */
|
ELUA_FUNCTION elua_debug( lua_State* L ) { /* Will add a log entry with debug severity */
|
||||||
/* ELUA_MOREARGS critical objects to be printed */
|
/* ELUA_MOREARGS debug objects to be printed */
|
||||||
elua_log(L,G_LOG_LEVEL_DEBUG);
|
elua_log(L,G_LOG_LEVEL_DEBUG);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue