diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2014-02-19 03:22:55 -0500 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2014-02-21 02:05:35 +0000 |
commit | 9246a709bf826f2cc64581b25fbf1ebafa330db6 (patch) | |
tree | b63eb4c55d7e1673f98a371d8787de906807baaf /epan/wslua/wslua_pinfo.c | |
parent | c65fbffc95b5e6b0caff6952faea8e8c9350cf7d (diff) | |
download | wireshark-9246a709bf826f2cc64581b25fbf1ebafa330db6.tar.gz |
Cleanup on aisle 5: normalizes the Lua code to follow common schema/model
Over time the various wslua classes/functions have gotten moldy, with different
ways of doing similar things. Some of it can't be changed without breaking
backwards compatibility for Lua scripts, so I didn't do that. But I did what
I could. The biggest change is a refactoring of how accessors/attributes
are handled in the code, so that most of them work the same way using the
same code.
Specific changes made:
* Added null/expired checking macro to class declarations for many classes
* Removed extraneous pointer/expired checking, since checkFoo() does that already
* Fixed "errors" reported by clang static analyzer; they were false positives, but it was easier to get it to stop complaining by changing the code
* Moved internal wslua functions from wslua_utils.c into a new 'wslua_internals.c' file
* Changed Listener/NSTime/Pinfo/Proto to use a common setter/getter accessor/attribute code model, instead of each of them doing their own
* Fixed some API doc mistakes, mostly around attributes that were documented as read-only but were actually read-write
Change-Id: Idddafc5fbd3545ebff29e063acc767e1c743a1a9
Reviewed-on: https://code.wireshark.org/review/271
Reviewed-by: Evan Huus <eapache@gmail.com>
Tested-by: Evan Huus <eapache@gmail.com>
Diffstat (limited to 'epan/wslua/wslua_pinfo.c')
-rw-r--r-- | epan/wslua/wslua_pinfo.c | 815 |
1 files changed, 261 insertions, 554 deletions
diff --git a/epan/wslua/wslua_pinfo.c b/epan/wslua/wslua_pinfo.c index 4f0b29981f..fd5df90418 100644 --- a/epan/wslua/wslua_pinfo.c +++ b/epan/wslua/wslua_pinfo.c @@ -71,7 +71,7 @@ Pinfo* push_Pinfo(lua_State* L, packet_info* ws_pinfo) { #define PUSH_COLUMNS(L,c) {g_ptr_array_add(outstanding_Columns,c);pushColumns(L,c);} #define PUSH_PRIVATE_TABLE(L,c) {g_ptr_array_add(outstanding_PrivateTable,c);pushPrivateTable(L,c);} -WSLUA_CLASS_DEFINE(NSTime,NOP,NOP); +WSLUA_CLASS_DEFINE(NSTime,FAIL_ON_NULL("NSTime"),NOP); /* NSTime represents a nstime_t. This is an object with seconds and nano seconds. */ WSLUA_CONSTRUCTOR NSTime_new(lua_State *L) { @@ -90,11 +90,16 @@ WSLUA_CONSTRUCTOR NSTime_new(lua_State *L) { WSLUA_RETURN(1); /* The new NSTime object. */ } +WSLUA_METAMETHOD NSTime__call(lua_State* L) { /* Creates a NSTime object */ +#define WSLUA_OPTARG_NSTime__call_SECONDS 1 /* Seconds */ +#define WSLUA_OPTARG_NSTime__call_NSECONDS 2 /* Nano seconds */ + lua_remove(L,1); /* remove the table */ + WSLUA_RETURN(NSTime_new(L)); /* The new NSTime object. */ +} + WSLUA_METAMETHOD NSTime__tostring(lua_State* L) { NSTime nstime = checkNSTime(L,1); - if (!nstime) return 0; - lua_pushstring(L,ep_strdup_printf("%ld.%09d", (long)nstime->secs, nstime->nsecs)); WSLUA_RETURN(1); /* The string representing the nstime. */ @@ -137,9 +142,6 @@ WSLUA_METAMETHOD NSTime__eq(lua_State* L) { /* Compares two NSTimes */ NSTime time2 = checkNSTime(L,2); gboolean result = FALSE; - if (!time1 || !time2) - WSLUA_ERROR(NSTime__eq,"Both values must be a NSTime"); - if (nstime_cmp(time1, time2) == 0) result = TRUE; @@ -153,9 +155,6 @@ WSLUA_METAMETHOD NSTime__le(lua_State* L) { /* Compares two NSTimes */ NSTime time2 = checkNSTime(L,2); gboolean result = FALSE; - if (!time1 || !time2) - WSLUA_ERROR(NSTime__le,"Both values must be a NSTime"); - if (nstime_cmp(time1, time2) <= 0) result = TRUE; @@ -169,9 +168,6 @@ WSLUA_METAMETHOD NSTime__lt(lua_State* L) { /* Compares two NSTimes */ NSTime time2 = checkNSTime(L,2); gboolean result = FALSE; - if (!time1 || !time2) - WSLUA_ERROR(NSTime__lt,"Both values must be a NSTime"); - if (nstime_cmp(time1, time2) < 0) result = TRUE; @@ -180,104 +176,18 @@ WSLUA_METAMETHOD NSTime__lt(lua_State* L) { /* Compares two NSTimes */ return 1; } -typedef struct { - const gchar* name; - lua_CFunction get; - lua_CFunction set; -} nstime_actions_t; - -static int NSTime_get_secs(lua_State* L) { - NSTime nstime = toNSTime(L,1); - - lua_pushnumber (L,(lua_Number)(nstime->secs)); - - return 1; -} - -static int NSTime_set_secs(lua_State* L) - { - NSTime nstime = toNSTime(L,1); - time_t secs = luaL_checkint(L,3); - - nstime->secs = secs; - - return 0; -} - -static int NSTime_get_nsecs(lua_State* L) { - NSTime nstime = toNSTime(L,1); - - lua_pushnumber (L,(lua_Number)(nstime->nsecs)); - - return 1; -} - -static int NSTime_set_nsecs(lua_State* L) { - NSTime nstime = toNSTime(L,1); - int nsecs = luaL_checkint(L,3); - - nstime->nsecs = nsecs; - - return 0; -} - -static const nstime_actions_t nstime_actions[] = { - /* WSLUA_ATTRIBUTE NSTime_secs RW The NSTime seconds */ - {"secs", NSTime_get_secs, NSTime_set_secs}, - - /* WSLUA_ATTRIBUTE NSTime_nsecs RW The NSTime nano seconds */ - {"nsecs", NSTime_get_nsecs, NSTime_set_nsecs}, - - {NULL,NULL,NULL} -}; - -static int NSTime__index(lua_State* L) { - NSTime nstime = checkNSTime(L,1); - const gchar* name = luaL_checkstring(L,2); - const nstime_actions_t* pa; - - if (! (nstime && name) ) return 0; - - for (pa = nstime_actions; pa->name; pa++) { - if ( g_str_equal(name,pa->name) ) { - if (pa->get) { - return pa->get(L); - } else { - luaL_error(L,"You cannot get the `%s' attribute of a nstime",name); - return 0; - } - } - } - luaL_error(L,"A protocol doesn't have a `%s' nstime",name); - return 0; -} +/* WSLUA_ATTRIBUTE NSTime_secs RW The NSTime seconds */ +WSLUA_ATTRIBUTE_NUMBER_GETTER(NSTime,secs); +WSLUA_ATTRIBUTE_NUMBER_SETTER(NSTime,secs,time_t); -static int NSTime__newindex(lua_State* L) { - NSTime nstime = checkNSTime(L,1); - const gchar* name = luaL_checkstring(L,2); - const nstime_actions_t* pa; - - if (! (nstime && name) ) return 0; - - for (pa = nstime_actions; pa->name; pa++) { - if ( g_str_equal(name,pa->name) ) { - if (pa->set) { - return pa->set(L); - } else { - luaL_error(L,"You cannot set the `%s' attribute of a nstime",name); - return 0; - } - } - } - - luaL_error(L,"A protocol doesn't have a `%s' nstime",name); - return 0; -} +/* WSLUA_ATTRIBUTE NSTime_nsecs RW The NSTime nano seconds */ +WSLUA_ATTRIBUTE_NUMBER_GETTER(NSTime,nsecs); +WSLUA_ATTRIBUTE_NUMBER_SETTER(NSTime,nsecs,int); /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */ static int NSTime__gc(lua_State* L) { - NSTime nstime = checkNSTime(L,1); + NSTime nstime = toNSTime(L,1); if (!nstime) return 0; @@ -285,29 +195,40 @@ static int NSTime__gc(lua_State* L) { return 0; } -WSLUA_META NSTime_meta[] = { - {"__index", NSTime__index}, - {"__newindex", NSTime__newindex}, - {"__tostring", NSTime__tostring}, - {"__add", NSTime__add}, - {"__sub", NSTime__sub}, - {"__unm", NSTime__unm}, - {"__eq", NSTime__eq}, - {"__le", NSTime__le}, - {"__lt", NSTime__lt}, - { NULL, NULL} +/* This table is ultimately registered as a sub-table of the class' metatable, + * and if __index/__newindex is invoked then it calls the appropriate function + * from this table for getting/setting the members. + */ +WSLUA_ATTRIBUTES NSTime_attributes[] = { + WSLUA_ATTRIBUTE_RWREG(NSTime,secs), + WSLUA_ATTRIBUTE_RWREG(NSTime,nsecs), + { NULL, NULL, NULL } }; -int NSTime_register(lua_State* L) { - WSLUA_REGISTER_META(NSTime); +WSLUA_METHODS NSTime_methods[] = { + WSLUA_CLASS_FNREG(NSTime,new), + { NULL, NULL } +}; - lua_pushcfunction(L, NSTime_new); - lua_setglobal(L, "NSTime"); +WSLUA_META NSTime_meta[] = { + WSLUA_CLASS_MTREG(NSTime,tostring), + WSLUA_CLASS_MTREG(NSTime,add), + WSLUA_CLASS_MTREG(NSTime,sub), + WSLUA_CLASS_MTREG(NSTime,unm), + WSLUA_CLASS_MTREG(NSTime,eq), + WSLUA_CLASS_MTREG(NSTime,le), + WSLUA_CLASS_MTREG(NSTime,lt), + WSLUA_CLASS_MTREG(NSTime,call), + { NULL, NULL } +}; +int NSTime_register(lua_State* L) { + WSLUA_REGISTER_CLASS(NSTime); + WSLUA_REGISTER_ATTRIBUTES(NSTime); return 0; } -WSLUA_CLASS_DEFINE(Address,NOP,NOP); /* Represents an address */ +WSLUA_CLASS_DEFINE(Address,FAIL_ON_NULL("Address"),NOP); /* Represents an address */ WSLUA_CONSTRUCTOR Address_ip(lua_State* L) { /* Creates an Address Object representing an IP address. */ @@ -452,7 +373,7 @@ WSLUA_METHODS Address_methods[] = { WSLUA_CLASS_FNREG(Address,uri), WSLUA_CLASS_FNREG(Address,tipc), #endif - {0,0} + { NULL, NULL } }; WSLUA_METAMETHOD Address__tostring(lua_State* L) { @@ -465,7 +386,7 @@ WSLUA_METAMETHOD Address__tostring(lua_State* L) { /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */ static int Address__gc(lua_State* L) { - Address addr = checkAddress(L,1); + Address addr = toAddress(L,1); if (addr) { g_free((void*)addr->data); @@ -515,11 +436,11 @@ WSLUA_METAMETHOD Address__lt(lua_State* L) { /* Compares two Addresses */ } WSLUA_META Address_meta[] = { - {"__tostring", Address__tostring }, - {"__eq",Address__eq}, - {"__le",Address__le}, - {"__lt",Address__lt}, - {0,0} + WSLUA_CLASS_MTREG(Address,tostring), + WSLUA_CLASS_MTREG(Address,eq), + WSLUA_CLASS_MTREG(Address,le), + WSLUA_CLASS_MTREG(Address,lt), + { NULL, NULL } }; @@ -529,7 +450,7 @@ int Address_register(lua_State *L) { } -WSLUA_CLASS_DEFINE(Column,FAIL_ON_NULL("expired column"),NOP); /* A Column in the packet list */ +WSLUA_CLASS_DEFINE(Column,FAIL_ON_NULL("Column"),NOP); /* A Column in the packet list */ struct col_names_t { const gchar* name; @@ -610,10 +531,7 @@ WSLUA_METAMETHOD Column__tostring(lua_State *L) { Column c = checkColumn(L,1); const gchar* text; - if (!c) { - lua_pushstring(L,"(nil)"); - } - else if (!c->cinfo) { + if (!c->cinfo) { text = col_id_to_name(c->col); lua_pushfstring(L, "(%s)", text ? text : "unknown"); } @@ -627,7 +545,7 @@ WSLUA_METAMETHOD Column__tostring(lua_State *L) { /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS */ static int Column__gc(lua_State* L) { - Column col = checkColumn(L,1); + Column col = toColumn(L,1); if (!col) return 0; @@ -644,7 +562,7 @@ WSLUA_METHOD Column_clear(lua_State *L) { /* Clears a Column */ Column c = checkColumn(L,1); - if (!(c && c->cinfo)) return 0; + if (!(c->cinfo)) return 0; col_clear(c->cinfo, c->col); @@ -657,7 +575,7 @@ WSLUA_METHOD Column_set(lua_State *L) { Column c = checkColumn(L,1); const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_set_TEXT); - if (!(c && c->cinfo)) + if (!(c->cinfo)) return 0; if (!s) WSLUA_ARG_ERROR(Column_set,TEXT,"must be a string"); @@ -673,7 +591,7 @@ WSLUA_METHOD Column_append(lua_State *L) { Column c = checkColumn(L,1); const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_append_TEXT); - if (!(c && c->cinfo)) + if (!(c->cinfo)) return 0; if (!s) WSLUA_ARG_ERROR(Column_append,TEXT,"must be a string"); @@ -689,7 +607,7 @@ WSLUA_METHOD Column_prepend(lua_State *L) { Column c = checkColumn(L,1); const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_prepend_TEXT); - if (!(c && c->cinfo)) + if (!(c->cinfo)) return 0; if (!s) WSLUA_ARG_ERROR(Column_prepend,TEXT,"must be a string"); @@ -703,21 +621,21 @@ WSLUA_METHOD Column_fence(lua_State *L) { /* Sets Column text fence, to prevent overwriting */ Column c = checkColumn(L,1); - if (c && c->cinfo) + if (c->cinfo) col_set_fence(c->cinfo, c->col); return 0; -} +} WSLUA_METHOD Column_clear_fence(lua_State *L) { /* Clear Column text fence */ Column c = checkColumn(L,1); - if (c && c->cinfo) + if (c->cinfo) col_clear_fence(c->cinfo, c->col); return 0; -} +} WSLUA_METHODS Column_methods[] = { @@ -728,13 +646,13 @@ WSLUA_METHODS Column_methods[] = { WSLUA_CLASS_FNREG_ALIAS(Column,preppend,prepend), WSLUA_CLASS_FNREG(Column,fence), WSLUA_CLASS_FNREG(Column,clear_fence), - {0,0} + { NULL, NULL } }; WSLUA_META Column_meta[] = { - {"__tostring", Column__tostring }, - {0,0} + WSLUA_CLASS_MTREG(Column,tostring), + { NULL, NULL } }; @@ -757,7 +675,7 @@ WSLUA_METAMETHOD Columns__tostring(lua_State *L) { /* The string "Columns", no real use, just for debugging purposes. */ } -/* +/* * To document this is very odd - it won't make sense to a person reading the * API docs to see this metamethod as a method, but oh well. */ @@ -789,7 +707,7 @@ WSLUA_METAMETHOD Columns__newindex(lua_State *L) { WSLUA_ARG_ERROR(Columns__newindex,COLUMN,"the column name must be a valid column"); } -WSLUA_METAMETHOD Columns_index(lua_State *L) { +WSLUA_METAMETHOD Columns__index(lua_State *L) { Columns cols = checkColumns(L,1); const struct col_names_t* cn; const char* colname = luaL_checkstring(L,2); @@ -798,7 +716,7 @@ WSLUA_METAMETHOD Columns_index(lua_State *L) { Column c = (Column)g_malloc(sizeof(struct _wslua_col_info)); c->cinfo = NULL; c->col = col_name_to_id(colname); - c->expired = FALSE; + c->expired = FALSE; PUSH_COLUMN(L,c); return 1; @@ -817,7 +735,7 @@ WSLUA_METAMETHOD Columns_index(lua_State *L) { Column c = (Column)g_malloc(sizeof(struct _wslua_col_info)); c->cinfo = cols->cinfo; c->col = col_name_to_id(colname); - c->expired = FALSE; + c->expired = FALSE; PUSH_COLUMN(L,c); return 1; @@ -829,7 +747,7 @@ WSLUA_METAMETHOD Columns_index(lua_State *L) { /* Gets registered as metamethod automatically by WSLUA_REGISTER_META */ static int Columns__gc(lua_State* L) { - Columns cols = checkColumns(L,1); + Columns cols = toColumns(L,1); if (!cols) return 0; @@ -843,10 +761,10 @@ static int Columns__gc(lua_State* L) { } -static const luaL_Reg Columns_meta[] = { - {"__tostring", Columns__tostring }, - {"__newindex", Columns__newindex }, - {"__index", Columns_index}, +WSLUA_META Columns_meta[] = { + WSLUA_CLASS_MTREG(Columns,tostring), + WSLUA_CLASS_MTREG(Columns,newindex), + WSLUA_CLASS_MTREG(Columns,index), { NULL, NULL } }; @@ -856,11 +774,11 @@ int Columns_register(lua_State *L) { return 0; } -WSLUA_CLASS_DEFINE(PrivateTable,NOP,NOP); +WSLUA_CLASS_DEFINE(PrivateTable,FAIL_ON_NULL_OR_EXPIRED("PrivateTable"),NOP); /* PrivateTable represents the pinfo->private_table. */ WSLUA_METAMETHOD PrivateTable__tostring(lua_State* L) { - PrivateTable priv = checkPrivateTable(L,1); + PrivateTable priv = toPrivateTable(L,1); GString *key_string; GList *keys, *key; @@ -891,13 +809,6 @@ static int PrivateTable__index(lua_State* L) { const gchar* name = luaL_checkstring(L,2); const gchar* string; - if (! (priv && name) ) return 0; - - if (priv->expired) { - luaL_error(L,"expired private_table"); - return 0; - } - string = (const gchar *)g_hash_table_lookup (priv->table, (gpointer) name); if (string) { @@ -915,13 +826,6 @@ static int PrivateTable__newindex(lua_State* L) { const gchar* name = luaL_checkstring(L,2); const gchar* string = NULL; - if (! (priv && name) ) return 0; - - if (priv->expired) { - luaL_error(L,"expired private_table"); - return 0; - } - if (lua_isstring(L,3)) { /* This also catches numbers, which is converted to string */ string = luaL_checkstring(L,3); @@ -944,7 +848,7 @@ static int PrivateTable__newindex(lua_State* L) { /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */ static int PrivateTable__gc(lua_State* L) { - PrivateTable priv = checkPrivateTable(L,1); + PrivateTable priv = toPrivateTable(L,1); if (!priv) return 0; @@ -961,10 +865,10 @@ static int PrivateTable__gc(lua_State* L) { } WSLUA_META PrivateTable_meta[] = { - {"__index", PrivateTable__index}, - {"__newindex", PrivateTable__newindex}, - {"__tostring", PrivateTable__tostring}, - { NULL, NULL} + WSLUA_CLASS_MTREG(PrivateTable,index), + WSLUA_CLASS_MTREG(PrivateTable,newindex), + WSLUA_CLASS_MTREG(PrivateTable,tostring), + { NULL, NULL } }; int PrivateTable_register(lua_State* L) { @@ -973,45 +877,38 @@ int PrivateTable_register(lua_State* L) { } -WSLUA_CLASS_DEFINE(Pinfo,FAIL_ON_NULL("expired pinfo"),NOP); +WSLUA_CLASS_DEFINE(Pinfo,FAIL_ON_NULL_OR_EXPIRED("Pinfo"),NOP); /* Packet information */ -static int Pinfo_tostring(lua_State *L) { lua_pushstring(L,"a Pinfo"); return 1; } - -#define PINFO_GET(name,block) static int name(lua_State *L) { \ - Pinfo pinfo = checkPinfo(L,1); \ - if (!pinfo) return 0;\ - if (pinfo->expired) { \ - luaL_error(L,"expired_pinfo"); \ - return 0; \ - } \ - block \ - return 1;\ -} - -#define PINFO_GET_BOOLEAN(name,val) \ - PINFO_GET(name,{lua_pushboolean(L,val);}) - -#define PINFO_GET_NUMBER(name,val) \ - PINFO_GET(name,{lua_pushnumber(L,(lua_Number)(val));}) +static int Pinfo__tostring(lua_State *L) { lua_pushstring(L,"a Pinfo"); return 1; } -#define PINFO_GET_STRING(name,val) \ - PINFO_GET(name, { \ - const gchar* value; \ - value = val; \ - if (value) lua_pushstring(L,(const char*)(value)); else lua_pushnil(L); \ +#define PINFO_ADDRESS_GETTER(name) \ + WSLUA_ATTRIBUTE_GET(Pinfo,name, { \ + Address addr = g_new(address,1); \ + COPY_ADDRESS(addr, &(obj->ws_pinfo->name)); \ + pushAddress(L,addr); \ }) -#define PINFO_GET_ADDRESS(name,role) \ - PINFO_GET(name, { \ - Address addr; \ - addr = g_new(address,1); \ - COPY_ADDRESS(addr, &(pinfo->ws_pinfo->role)); \ - pushAddress(L,addr); \ +#define PINFO_ADDRESS_SETTER(name) \ + WSLUA_ATTRIBUTE_SET(Pinfo,name, { \ + const address* from = checkAddress(L,-1); \ + COPY_ADDRESS(&(obj->ws_pinfo->name),from); \ }) -#define PINFO_GET_LIGHTUSERDATA(name, val) \ - PINFO_GET(name,{lua_pushlightuserdata(L, (void *) (val));}) +#define PINFO_NAMED_BOOLEAN_GETTER(name,member) \ + WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(Pinfo,name,ws_pinfo->member) + +#define PINFO_NUMBER_GETTER(name) \ + WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(Pinfo,name,ws_pinfo->name) + +#define PINFO_NAMED_NUMBER_GETTER(name,member) \ + WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(Pinfo,name,ws_pinfo->member) + +#define PINFO_NUMBER_SETTER(name,cast) \ + WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(Pinfo,name,ws_pinfo->name,cast) + +#define PINFO_NAMED_NUMBER_SETTER(name,member,cast) \ + WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(Pinfo,name,ws_pinfo->member,cast) static double lua_nstime_to_sec(const nstime_t *nstime) @@ -1028,47 +925,107 @@ lua_delta_nstime_to_sec(const Pinfo pinfo, const frame_data *fd, guint32 prev_nu return lua_nstime_to_sec(&del); } -PINFO_GET_BOOLEAN(Pinfo_fragmented,pinfo->ws_pinfo->fragmented) -PINFO_GET_BOOLEAN(Pinfo_in_error_pkt,pinfo->ws_pinfo->flags.in_error_pkt) -PINFO_GET_BOOLEAN(Pinfo_visited,pinfo->ws_pinfo->fd->flags.visited) - -PINFO_GET_NUMBER(Pinfo_number,pinfo->ws_pinfo->fd->num) -PINFO_GET_NUMBER(Pinfo_len,pinfo->ws_pinfo->fd->pkt_len) -PINFO_GET_NUMBER(Pinfo_caplen,pinfo->ws_pinfo->fd->cap_len) -PINFO_GET_NUMBER(Pinfo_abs_ts,lua_nstime_to_sec(&pinfo->ws_pinfo->fd->abs_ts)) -PINFO_GET_NUMBER(Pinfo_rel_ts,lua_nstime_to_sec(&pinfo->ws_pinfo->rel_ts)) -PINFO_GET_NUMBER(Pinfo_delta_ts,lua_delta_nstime_to_sec(pinfo, pinfo->ws_pinfo->fd, pinfo->ws_pinfo->fd->num - 1)) -PINFO_GET_NUMBER(Pinfo_delta_dis_ts,lua_delta_nstime_to_sec(pinfo, pinfo->ws_pinfo->fd, pinfo->ws_pinfo->fd->prev_dis_num)) -PINFO_GET_NUMBER(Pinfo_ipproto,pinfo->ws_pinfo->ipproto) -PINFO_GET_NUMBER(Pinfo_circuit_id,pinfo->ws_pinfo->circuit_id) -PINFO_GET_NUMBER(Pinfo_can_desegment,pinfo->ws_pinfo->can_desegment) -PINFO_GET_NUMBER(Pinfo_desegment_len,pinfo->ws_pinfo->desegment_len) -PINFO_GET_NUMBER(Pinfo_desegment_offset,pinfo->ws_pinfo->desegment_offset) -PINFO_GET_NUMBER(Pinfo_ptype,pinfo->ws_pinfo->ptype) -PINFO_GET_NUMBER(Pinfo_src_port,pinfo->ws_pinfo->srcport) -PINFO_GET_NUMBER(Pinfo_dst_port,pinfo->ws_pinfo->destport) -PINFO_GET_NUMBER(Pinfo_match_uint,pinfo->ws_pinfo->match_uint) - -PINFO_GET_STRING(Pinfo_curr_proto,pinfo->ws_pinfo->current_proto) -PINFO_GET_STRING(Pinfo_match_string,pinfo->ws_pinfo->match_string) - -PINFO_GET_ADDRESS(Pinfo_net_src,net_src) -PINFO_GET_ADDRESS(Pinfo_net_dst,net_dst) -PINFO_GET_ADDRESS(Pinfo_dl_src,dl_src) -PINFO_GET_ADDRESS(Pinfo_dl_dst,dl_dst) -PINFO_GET_ADDRESS(Pinfo_src,src) -PINFO_GET_ADDRESS(Pinfo_dst,dst) - -PINFO_GET_LIGHTUSERDATA(Pinfo_private_data, pinfo->ws_pinfo->private_data) - -static int Pinfo_match(lua_State *L) { - Pinfo pinfo = checkPinfo(L,1); - if (!pinfo) return 0; - if (pinfo->expired) { - luaL_error(L,"expired_pinfo"); - return 0; - } +/* WSLUA_ATTRIBUTE Pinfo_visited RO Whether this packet hass been already visited */ +PINFO_NAMED_BOOLEAN_GETTER(visited,fd->flags.visited); + +/* WSLUA_ATTRIBUTE Pinfo_number RO The number of this packet in the current file */ +PINFO_NAMED_NUMBER_GETTER(number,fd->num); + +/* WSLUA_ATTRIBUTE Pinfo_len RO The length of the frame */ +PINFO_NAMED_NUMBER_GETTER(len,fd->pkt_len); + +/* WSLUA_ATTRIBUTE Pinfo_caplen RO The captured length of the frame */ +PINFO_NAMED_NUMBER_GETTER(caplen,fd->cap_len); + +/* WSLUA_ATTRIBUTE Pinfo_abs_ts RO When the packet was captured */ +WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(Pinfo,abs_ts,lua_nstime_to_sec(&obj->ws_pinfo->fd->abs_ts)); + +/* WSLUA_ATTRIBUTE Pinfo_rel_ts RO Number of seconds passed since beginning of capture */ +WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(Pinfo,rel_ts,lua_nstime_to_sec(&obj->ws_pinfo->rel_ts)); + +/* WSLUA_ATTRIBUTE Pinfo_delta_ts RO Number of seconds passed since the last captured packet */ +WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(Pinfo,delta_ts,lua_delta_nstime_to_sec(obj, obj->ws_pinfo->fd, obj->ws_pinfo->fd->num - 1)); + +/* WSLUA_ATTRIBUTE Pinfo_delta_dis_ts RO Number of seconds passed since the last displayed packet */ +WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(Pinfo,delta_dis_ts,lua_delta_nstime_to_sec(obj, obj->ws_pinfo->fd, obj->ws_pinfo->fd->prev_dis_num)); + +/* WSLUA_ATTRIBUTE Pinfo_ipproto RO IP Protocol id */ +PINFO_NUMBER_GETTER(ipproto); + +/* WSLUA_ATTRIBUTE Pinfo_circuit_id RW For circuit based protocols */ +PINFO_NUMBER_GETTER(circuit_id); +PINFO_NUMBER_SETTER(circuit_id,guint32); + +/* WSLUA_ATTRIBUTE Pinfo_curr_proto RO Which Protocol are we dissecting */ +WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(Pinfo,curr_proto,ws_pinfo->current_proto); + +/* WSLUA_ATTRIBUTE Pinfo_can_desegment RW Set if this segment could be desegmented */ +PINFO_NUMBER_GETTER(can_desegment); +PINFO_NUMBER_SETTER(can_desegment,guint16); + +/* WSLUA_ATTRIBUTE Pinfo_desegment_len RW Estimated number of additional bytes required for completing the PDU */ +PINFO_NUMBER_GETTER(desegment_len); +PINFO_NUMBER_SETTER(desegment_len,guint32); + +/* WSLUA_ATTRIBUTE Pinfo_desegment_offset RW Offset in the tvbuff at which the dissector will continue processing when next called*/ +PINFO_NUMBER_GETTER(desegment_offset); +PINFO_NUMBER_SETTER(desegment_offset,int); + +/* WSLUA_ATTRIBUTE Pinfo_private_data RO Access to private data */ +WSLUA_ATTRIBUTE_GET(Pinfo,private_data, {lua_pushlightuserdata(L,(void *)(obj->ws_pinfo->private_data));}); + +/* WSLUA_ATTRIBUTE Pinfo_fragmented RO If the protocol is only a fragment */ +PINFO_NAMED_BOOLEAN_GETTER(fragmented,fragmented); + +/* WSLUA_ATTRIBUTE Pinfo_in_error_pkt RO If we're inside an error packet */ +PINFO_NAMED_BOOLEAN_GETTER(in_error_pkt,flags.in_error_pkt); + +/* WSLUA_ATTRIBUTE Pinfo_match_uint RO Matched uint for calling subdissector from table */ +PINFO_NUMBER_GETTER(match_uint); + +/* WSLUA_ATTRIBUTE Pinfo_match_string RO Matched string for calling subdissector from table */ +WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(Pinfo,match_string,ws_pinfo->match_string); + +/* WSLUA_ATTRIBUTE Pinfo_port_type RW Type of Port of .src_port and .dst_port */ +PINFO_NAMED_NUMBER_GETTER(port_type,ptype); + +/* WSLUA_ATTRIBUTE Pinfo_src_port RW Source Port of this Packet */ +PINFO_NAMED_NUMBER_GETTER(src_port,srcport); +PINFO_NAMED_NUMBER_SETTER(src_port,srcport,guint32); + +/* WSLUA_ATTRIBUTE Pinfo_dst_port RW Source Address of this Packet */ +PINFO_NAMED_NUMBER_GETTER(dst_port,destport); +PINFO_NAMED_NUMBER_SETTER(dst_port,destport,guint32); + +/* WSLUA_ATTRIBUTE Pinfo_dl_src RW Data Link Source Address of this Packet */ +PINFO_ADDRESS_GETTER(dl_src); +PINFO_ADDRESS_SETTER(dl_src); + +/* WSLUA_ATTRIBUTE Pinfo_dl_dst RW Data Link Destination Address of this Packet */ +PINFO_ADDRESS_GETTER(dl_dst); +PINFO_ADDRESS_SETTER(dl_dst); + +/* WSLUA_ATTRIBUTE Pinfo_net_src RW Network Layer Source Address of this Packet */ +PINFO_ADDRESS_GETTER(net_src); +PINFO_ADDRESS_SETTER(net_src); + +/* WSLUA_ATTRIBUTE Pinfo_net_dst RW Network Layer Destination Address of this Packet */ +PINFO_ADDRESS_GETTER(net_dst); +PINFO_ADDRESS_SETTER(net_dst); + +/* WSLUA_ATTRIBUTE Pinfo_src RW Source Address of this Packet */ +PINFO_ADDRESS_GETTER(src); +PINFO_ADDRESS_SETTER(src); + +/* WSLUA_ATTRIBUTE Pinfo_dst RW Destination Address of this Packet */ +PINFO_ADDRESS_GETTER(dst); +PINFO_ADDRESS_SETTER(dst); + + +/* WSLUA_ATTRIBUTE Pinfo_match RO Port/Data we are matching */ +static int Pinfo_get_match(lua_State *L) { + Pinfo pinfo = checkPinfo(L,1); if (pinfo->ws_pinfo->match_string) { lua_pushstring(L,pinfo->ws_pinfo->match_string); @@ -1079,16 +1036,13 @@ static int Pinfo_match(lua_State *L) { return 1; } -static int Pinfo_columns(lua_State *L) { +/* WSLUA_ATTRIBUTE Pinfo_columns RO Accesss to the packet list columns */ +/* WSLUA_ATTRIBUTE Pinfo_cols RO Accesss to the packet list columns (equivalent to pinfo.columns) */ +static int Pinfo_get_columns(lua_State *L) { Columns cols = NULL; Pinfo pinfo = checkPinfo(L,1); const gchar* colname = luaL_optstring(L,2,NULL); - if (pinfo->expired) { - luaL_error(L,"expired_pinfo"); - return 0; - } - cols = (Columns)g_malloc(sizeof(struct _wslua_cols)); cols->cinfo = pinfo->ws_pinfo->cinfo; cols->expired = FALSE; @@ -1099,24 +1053,18 @@ static int Pinfo_columns(lua_State *L) { lua_settop(L,0); PUSH_COLUMNS(L,cols); lua_pushstring(L,colname); - return Columns_index(L); + return Columns__index(L); } return 1; } -static int Pinfo_private(lua_State *L) { +/* WSLUA_ATTRIBUTE Pinfo_private RO Access to the private table entries */ +static int Pinfo_get_private(lua_State *L) { PrivateTable priv = NULL; Pinfo pinfo = checkPinfo(L,1); const gchar* privname = luaL_optstring(L,2,NULL); gboolean is_allocated = FALSE; - if (!pinfo) return 0; - - if (pinfo->expired) { - luaL_error(L,"expired private_table"); - return 0; - } - if (!pinfo->ws_pinfo->private_table) { pinfo->ws_pinfo->private_table = g_hash_table_new(g_str_hash,g_str_equal); is_allocated = TRUE; @@ -1138,121 +1086,11 @@ static int Pinfo_private(lua_State *L) { return 1; } -typedef enum { - PARAM_NONE, - PARAM_ADDR_SRC, - PARAM_ADDR_DST, - PARAM_ADDR_DL_SRC, - PARAM_ADDR_DL_DST, - PARAM_ADDR_NET_SRC, - PARAM_ADDR_NET_DST, - PARAM_PORT_SRC, - PARAM_PORT_DST, - PARAM_CIRCUIT_ID, - PARAM_CAN_DESEGMENT, - PARAM_DESEGMENT_LEN, - PARAM_DESEGMENT_OFFSET, - PARAM_PORT_TYPE -} pinfo_param_type_t; - -static int pushnil_param(lua_State* L, packet_info* pinfo _U_, pinfo_param_type_t pt _U_ ) { - lua_pushnil(L); - return 1; -} - -static int Pinfo_set_addr(lua_State* L, packet_info* pinfo, pinfo_param_type_t pt) { - const address* from = checkAddress(L,1); - address* to; - - if (! from ) { - luaL_error(L,"Not an OK address"); - return 0; - } - - if (!pinfo) { - luaL_error(L,"expired_pinfo"); - return 0; - } - - switch(pt) { - case PARAM_ADDR_SRC: - to = &(pinfo->src); - break; - case PARAM_ADDR_DST: - to = &(pinfo->dst); - break; - case PARAM_ADDR_DL_SRC: - to = &(pinfo->dl_src); - break; - case PARAM_ADDR_DL_DST: - to = &(pinfo->dl_dst); - break; - case PARAM_ADDR_NET_SRC: - to = &(pinfo->net_src); - break; - case PARAM_ADDR_NET_DST: - to = &(pinfo->net_dst); - break; - default: - g_assert(!"BUG: A bad parameter"); - return 0; - } - - COPY_ADDRESS(to,from); - return 0; -} - -static int Pinfo_set_int(lua_State* L, packet_info* pinfo, pinfo_param_type_t pt) { - gint64 v = luaL_checkint(L,1); - - if (!pinfo) { - luaL_error(L,"expired_pinfo"); - return 0; - } - - switch(pt) { - case PARAM_PORT_SRC: - pinfo->srcport = (guint32)v; - return 0; - case PARAM_PORT_DST: - pinfo->destport = (guint32)v; - return 0; - case PARAM_CIRCUIT_ID: - pinfo->circuit_id = (guint32)v; - return 0; - case PARAM_CAN_DESEGMENT: - pinfo->can_desegment = (guint16)v; - return 0; - case PARAM_DESEGMENT_LEN: - pinfo->desegment_len = (guint32)v; - return 0; - case PARAM_DESEGMENT_OFFSET: - pinfo->desegment_offset = (int)v; - return 0; - default: - g_assert(!"BUG: A bad parameter"); - } - - return 0; -} - -typedef struct _pinfo_method_t { - const gchar* name; - lua_CFunction get; - int (*set)(lua_State*, packet_info*, pinfo_param_type_t); - pinfo_param_type_t param; -} pinfo_method_t; - -static int Pinfo_hi(lua_State *L) { +/* WSLUA_ATTRIBUTE Pinfo_hi RW higher Address of this Packet */ +static int Pinfo_get_hi(lua_State *L) { Pinfo pinfo = checkPinfo(L,1); Address addr; - if (!pinfo) return 0; - if (pinfo->expired) { - luaL_error(L,"expired_pinfo"); - return 0; - } - addr = (Address)g_malloc(sizeof(address)); if (CMP_ADDRESS(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) >= 0) { COPY_ADDRESS(addr, &(pinfo->ws_pinfo->src)); @@ -1264,16 +1102,11 @@ static int Pinfo_hi(lua_State *L) { return 1; } -static int Pinfo_lo(lua_State *L) { +/* WSLUA_ATTRIBUTE Pinfo_lo RO lower Address of this Packet */ +static int Pinfo_get_lo(lua_State *L) { Pinfo pinfo = checkPinfo(L,1); Address addr; - if (!pinfo) return 0; - if (pinfo->expired) { - luaL_error(L,"expired_pinfo"); - return 0; - } - addr = (Address)g_malloc(sizeof(address)); if (CMP_ADDRESS(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) < 0) { COPY_ADDRESS(addr, &(pinfo->ws_pinfo->src)); @@ -1285,177 +1118,9 @@ static int Pinfo_lo(lua_State *L) { return 1; } - -static const pinfo_method_t Pinfo_methods[] = { - - /* WSLUA_ATTRIBUTE Pinfo_number RO The number of this packet in the current file */ - {"number", Pinfo_number, pushnil_param, PARAM_NONE}, - - /* WSLUA_ATTRIBUTE Pinfo_len RO The length of the frame */ - {"len", Pinfo_len, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_caplen RO The captured length of the frame */ - {"caplen", Pinfo_caplen, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_abs_ts RO When the packet was captured */ - {"abs_ts",Pinfo_abs_ts, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_rel_ts RO Number of seconds passed since beginning of capture */ - {"rel_ts",Pinfo_rel_ts, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_delta_ts RO Number of seconds passed since the last captured packet */ - {"delta_ts",Pinfo_delta_ts, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_delta_dis_ts RO Number of seconds passed since the last displayed packet */ - {"delta_dis_ts",Pinfo_delta_dis_ts, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_visited RO Whether this packet hass been already visited */ - {"visited",Pinfo_visited, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_src RW Source Address of this Packet */ - {"src", Pinfo_src, Pinfo_set_addr, PARAM_ADDR_SRC }, - - /* WSLUA_ATTRIBUTE Pinfo_dst RW Destination Address of this Packet */ - {"dst", Pinfo_dst, Pinfo_set_addr, PARAM_ADDR_DST }, - - /* WSLUA_ATTRIBUTE Pinfo_lo RO lower Address of this Packet */ - {"lo", Pinfo_lo, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_hi RW higher Address of this Packet */ - {"hi", Pinfo_hi, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_dl_src RW Data Link Source Address of this Packet */ - {"dl_src", Pinfo_dl_src, Pinfo_set_addr, PARAM_ADDR_DL_SRC }, - - /* WSLUA_ATTRIBUTE Pinfo_dl_dst RW Data Link Destination Address of this Packet */ - {"dl_dst", Pinfo_dl_dst, Pinfo_set_addr, PARAM_ADDR_DL_DST }, - - /* WSLUA_ATTRIBUTE Pinfo_net_src RW Network Layer Source Address of this Packet */ - {"net_src", Pinfo_net_src, Pinfo_set_addr, PARAM_ADDR_NET_SRC }, - - /* WSLUA_ATTRIBUTE Pinfo_net_dst RW Network Layer Destination Address of this Packet */ - {"net_dst", Pinfo_net_dst, Pinfo_set_addr, PARAM_ADDR_NET_DST }, - - /* WSLUA_ATTRIBUTE Pinfo_ptype RW Type of Port of .src_port and .dst_port */ - {"port_type", Pinfo_ptype, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_src_port RW Source Port of this Packet */ - {"src_port", Pinfo_src_port, Pinfo_set_int, PARAM_PORT_SRC }, - - /* WSLUA_ATTRIBUTE Pinfo_dst_port RW Source Address of this Packet */ - {"dst_port", Pinfo_dst_port, Pinfo_set_int, PARAM_PORT_DST }, - - /* WSLUA_ATTRIBUTE Pinfo_ipproto RO IP Protocol id */ - {"ipproto", Pinfo_ipproto, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_circuit_id RO For circuit based protocols */ - {"circuit_id", Pinfo_circuit_id, Pinfo_set_int, PARAM_CIRCUIT_ID }, - - /* WSLUA_ATTRIBUTE Pinfo_match RO Port/Data we are matching */ - {"match", Pinfo_match, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_curr_proto RO Which Protocol are we dissecting */ - {"curr_proto", Pinfo_curr_proto, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_columns RO Accesss to the packet list columns */ - {"columns", Pinfo_columns, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_cols RO Accesss to the packet list columns (equivalent to pinfo.columns) */ - {"cols", Pinfo_columns, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_can_desegment RW Set if this segment could be desegmented */ - {"can_desegment", Pinfo_can_desegment, Pinfo_set_int, PARAM_CAN_DESEGMENT }, - - /* WSLUA_ATTRIBUTE Pinfo_desegment_len RW Estimated number of additional bytes required for completing the PDU */ - {"desegment_len", Pinfo_desegment_len, Pinfo_set_int, PARAM_DESEGMENT_LEN }, - - /* WSLUA_ATTRIBUTE Pinfo_desegment_offset RW Offset in the tvbuff at which the dissector will continue processing when next called*/ - {"desegment_offset", Pinfo_desegment_offset, Pinfo_set_int, PARAM_DESEGMENT_OFFSET }, - - /* WSLUA_ATTRIBUTE Pinfo_private_data RO Access to private data */ - {"private_data", Pinfo_private_data, pushnil_param, PARAM_NONE}, - - /* WSLUA_ATTRIBUTE Pinfo_private RW Access to the private table entries */ - {"private", Pinfo_private, pushnil_param, PARAM_NONE}, - - /* WSLUA_ATTRIBUTE Pinfo_fragmented RO If the protocol is only a fragment */ - {"fragmented", Pinfo_fragmented, pushnil_param, PARAM_NONE}, - - /* WSLUA_ATTRIBUTE Pinfo_in_error_pkt RO If we're inside an error packet */ - {"in_error_pkt", Pinfo_in_error_pkt, pushnil_param, PARAM_NONE}, - - /* WSLUA_ATTRIBUTE Pinfo_match_uint RO Matched uint for calling subdissector from table */ - {"match_uint", Pinfo_match_uint, pushnil_param, PARAM_NONE }, - - /* WSLUA_ATTRIBUTE Pinfo_match_string RO Matched string for calling subdissector from table */ - {"match_string", Pinfo_match_string, pushnil_param, PARAM_NONE }, - - {NULL,NULL,NULL,PARAM_NONE} -}; - - -static int pushnil(lua_State* L) { - lua_pushnil(L); - return 1; -} - -static int Pinfo_index(lua_State* L) { - Pinfo pinfo = checkPinfo(L,1); - const gchar* name = luaL_checkstring(L,2); - lua_CFunction method = pushnil; - const pinfo_method_t* curr; - - if (! (pinfo && name) ) { - lua_pushnil(L); - return 1; - } - if (pinfo->expired) { - luaL_error(L,"expired_pinfo"); - return 0; - } - - for (curr = Pinfo_methods ; curr->name ; curr++) { - if (g_str_equal(curr->name,name)) { - method = curr->get; - break; - } - } - - lua_settop(L,1); - return method(L); -} - -static int Pinfo_setindex(lua_State* L) { - Pinfo pinfo = checkPinfo(L,1); - const gchar* name = luaL_checkstring(L,2); - int (*method)(lua_State*, packet_info* pinfo, pinfo_param_type_t) = pushnil_param; - const pinfo_method_t* curr; - pinfo_param_type_t param_type = PARAM_NONE; - - if (! (pinfo && name) ) { - return 0; - } - if (pinfo->expired) { - luaL_error(L,"expired_pinfo"); - return 0; - } - - for (curr = Pinfo_methods ; curr->name ; curr++) { - if (g_str_equal(curr->name,name)) { - method = curr->set; - param_type = curr->param; - break; - } - } - - lua_remove(L,1); - lua_remove(L,1); - return method(L,pinfo->ws_pinfo,param_type); -} - /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */ static int Pinfo__gc(lua_State* L) { - Pinfo pinfo = checkPinfo(L,1); + Pinfo pinfo = toPinfo(L,1); if (!pinfo) return 0; @@ -1468,15 +1133,57 @@ static int Pinfo__gc(lua_State* L) { } -static const luaL_Reg Pinfo_meta[] = { - {"__index", Pinfo_index}, - {"__newindex",Pinfo_setindex}, - {"__tostring", Pinfo_tostring}, +/* This table is ultimately registered as a sub-table of the class' metatable, + * and if __index/__newindex is invoked then it calls the appropriate function + * from this table for getting/setting the members. + */ +WSLUA_ATTRIBUTES Pinfo_attributes[] = { + WSLUA_ATTRIBUTE_ROREG(Pinfo,number), + WSLUA_ATTRIBUTE_ROREG(Pinfo,len), + WSLUA_ATTRIBUTE_ROREG(Pinfo,caplen), + WSLUA_ATTRIBUTE_ROREG(Pinfo,abs_ts), + WSLUA_ATTRIBUTE_ROREG(Pinfo,rel_ts), + WSLUA_ATTRIBUTE_ROREG(Pinfo,delta_ts), + WSLUA_ATTRIBUTE_ROREG(Pinfo,delta_dis_ts), + WSLUA_ATTRIBUTE_ROREG(Pinfo,visited), + WSLUA_ATTRIBUTE_RWREG(Pinfo,src), + WSLUA_ATTRIBUTE_RWREG(Pinfo,dst), + WSLUA_ATTRIBUTE_ROREG(Pinfo,lo), + WSLUA_ATTRIBUTE_ROREG(Pinfo,hi), + WSLUA_ATTRIBUTE_RWREG(Pinfo,dl_src), + WSLUA_ATTRIBUTE_RWREG(Pinfo,dl_dst), + WSLUA_ATTRIBUTE_RWREG(Pinfo,net_src), + WSLUA_ATTRIBUTE_RWREG(Pinfo,net_dst), + WSLUA_ATTRIBUTE_ROREG(Pinfo,port_type), + WSLUA_ATTRIBUTE_RWREG(Pinfo,src_port), + WSLUA_ATTRIBUTE_RWREG(Pinfo,dst_port), + WSLUA_ATTRIBUTE_ROREG(Pinfo,ipproto), + WSLUA_ATTRIBUTE_RWREG(Pinfo,circuit_id), + WSLUA_ATTRIBUTE_ROREG(Pinfo,match), + WSLUA_ATTRIBUTE_ROREG(Pinfo,curr_proto), + WSLUA_ATTRIBUTE_ROREG(Pinfo,columns), + { "cols", Pinfo_get_columns, NULL }, + WSLUA_ATTRIBUTE_RWREG(Pinfo,can_desegment), + WSLUA_ATTRIBUTE_RWREG(Pinfo,desegment_len), + WSLUA_ATTRIBUTE_RWREG(Pinfo,desegment_offset), + WSLUA_ATTRIBUTE_ROREG(Pinfo,private_data), + WSLUA_ATTRIBUTE_ROREG(Pinfo,private), + WSLUA_ATTRIBUTE_ROREG(Pinfo,fragmented), + WSLUA_ATTRIBUTE_ROREG(Pinfo,in_error_pkt), + WSLUA_ATTRIBUTE_ROREG(Pinfo,fragmented), + WSLUA_ATTRIBUTE_ROREG(Pinfo,match_uint), + WSLUA_ATTRIBUTE_ROREG(Pinfo,match_string), + { NULL, NULL, NULL } +}; + +WSLUA_META Pinfo_meta[] = { + WSLUA_CLASS_MTREG(Pinfo,tostring), { NULL, NULL } }; int Pinfo_register(lua_State* L) { WSLUA_REGISTER_META(Pinfo); + WSLUA_REGISTER_ATTRIBUTES(Pinfo); outstanding_Pinfo = g_ptr_array_new(); outstanding_Column = g_ptr_array_new(); outstanding_Columns = g_ptr_array_new(); |