diff options
author | lego <lego@f5534014-38df-0310-8fa8-9805f1628bb7> | 2006-01-24 23:22:52 +0000 |
---|---|---|
committer | lego <lego@f5534014-38df-0310-8fa8-9805f1628bb7> | 2006-01-24 23:22:52 +0000 |
commit | ba63721601a3c8fd2af5e26b7b552e8cbf103902 (patch) | |
tree | e408603921d9a6fa56b4a113440ded64424fb07a /plugins | |
parent | 89e34667df69b506b7c917bf9855fbb58347e393 (diff) |
an Address class, changed the names of some classes, modified pinfo to be a table
pinfo.src = Address.ip("www.xxx.com")
pinfo.col.info = "A special packet"
if (pinfo.src_port == 2) then pinfo.col.protocol = "STRANGE" end
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@17096 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/lua/lua_pinfo.c | 483 | ||||
-rw-r--r-- | plugins/lua/lua_proto.c | 104 | ||||
-rw-r--r-- | plugins/lua/lua_tap.c | 40 | ||||
-rw-r--r-- | plugins/lua/lua_tree.c | 122 | ||||
-rw-r--r-- | plugins/lua/packet-lua.c | 39 | ||||
-rw-r--r-- | plugins/lua/packet-lua.h | 33 |
6 files changed, 590 insertions, 231 deletions
diff --git a/plugins/lua/lua_pinfo.c b/plugins/lua/lua_pinfo.c index d90f2413f7..d6ba4a6a74 100644 --- a/plugins/lua/lua_pinfo.c +++ b/plugins/lua/lua_pinfo.c @@ -27,10 +27,196 @@ */ #include "packet-lua.h" +#include <epan/addr_resolv.h> +#include <string.h> -LUA_CLASS_DEFINE(Column,COLUMN,if (! *p) luaL_error(L,"null column")); +LUA_CLASS_DEFINE(Column,COLUMN,NOP); LUA_CLASS_DEFINE(Columns,COLUMNS,NOP); LUA_CLASS_DEFINE(Pinfo,PINFO,if (! *p) luaL_error(L,"null pinfo")); +LUA_CLASS_DEFINE(Address,ADDRESS,NOP); + +static int Address_ip(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + guint32* ip_addr = g_malloc(sizeof(guint32)); + const gchar* name = luaL_checkstring(L,1); + + if (! get_host_ipaddr(name, (guint32*)ip_addr)) { + *ip_addr = 0; + } + + SET_ADDRESS(addr, AT_IPv4, 4, ip_addr); + pushAddress(L,addr); + return 1; +} + +#if 0 +/* TODO */ +static int Address_ipv6(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_ss7(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_eth(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_sna(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_atalk(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_vines(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_osi(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_arcnet(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_fc(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_string(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_eui64(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_uri(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +static int Address_tipc(lua_State* L) { + Address addr = g_malloc(sizeof(address)); + + SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4)); + + pushAddress(L,addr); + return 1; +} +#endif + +static const luaL_reg Address_methods[] = { + {"ip", Address_ip }, +#if 0 + {"ipv6", Address_ipv6 }, + {"ss7pc", Address_ss7 }, + {"eth", Address_eth }, + {"sna", Address_sna }, + {"atalk", Address_atalk }, + {"vines", Address_vines }, + {"osi", Address_osi }, + {"arcnet", Address_arcnet }, + {"fc", Address_fc }, + {"string", Address_string }, + {"eui64", Address_eui64 }, + {"uri", Address_uri }, + {"tipc", Address_tipc }, +#endif + {0,0} +}; + +static int Address_tostring(lua_State* L) { + Address addr = checkAddress(L,1); + + lua_pushstring(L,get_addr_name(addr)); + + return 1; +} + +static int Address_gc(lua_State* L) { + Address addr = checkAddress(L,1); + + if (addr) { + if (addr->data) g_free((void*)addr->data); + g_free((void*)addr); + } + + return 0; +} + +static const luaL_reg Address_meta[] = { + {"__gc", Address_gc }, + {"__tostring", Address_tostring }, + {0,0} +}; + + +int Address_register(lua_State *L) { + luaL_openlib(L, ADDRESS, Address_methods, 0); + luaL_newmetatable(L, ADDRESS); + luaL_openlib(L, 0, Address_meta, 0); + lua_pushliteral(L, "__index"); + lua_pushvalue(L, -3); + lua_rawset(L, -3); + lua_pushliteral(L, "__metatable"); + lua_pushvalue(L, -3); + lua_rawset(L, -3); + lua_pop(L, 1); + + return 1; +} /* Column class */ struct col_names_t { @@ -114,18 +300,21 @@ static int Column_tostring(lua_State *L) { Column c = checkColumn(L,1); const gchar* name; - if (!c) return 0; - - name = col_id_to_name(c->col); + if (!(c && c->cinfo)) { + lua_pushstring(L,"Bad Column"); + return 1; + } else { + name = col_id_to_name(c->col); + lua_pushstring(L,name ? name : "Unknown Column"); + } - lua_pushstring(L,name ? name : "Unknown Column"); return 1; } static int Column_clear(lua_State *L) { Column c = checkColumn(L,1); - if (!c) return 0; + if (!(c && c->cinfo)) return 0; if (check_col(c->cinfo, c->col)) col_clear(c->cinfo, c->col); @@ -137,7 +326,7 @@ static int Column_set(lua_State *L) { Column c = checkColumn(L,1); const gchar* s = luaL_checkstring(L,2); - if (!c) return 0; + if (!(c && c->cinfo && s)) return 0; if (check_col(c->cinfo, c->col)) col_set_str(c->cinfo, c->col, s); @@ -149,7 +338,7 @@ static int Column_append(lua_State *L) { Column c = checkColumn(L,1); const gchar* s = luaL_checkstring(L,2); - if (!(c && s)) return 0; + if (!(c && c->cinfo && s)) return 0; if (check_col(c->cinfo, c->col)) col_append_str(c->cinfo, c->col, s); @@ -160,7 +349,7 @@ static int Column_preppend(lua_State *L) { Column c = checkColumn(L,1); const gchar* s = luaL_checkstring(L,2); - if (!(c && s)) return 0; + if (!(c && c->cinfo && s)) return 0; if (check_col(c->cinfo, c->col)) col_prepend_fstr(c->cinfo, c->col, "%s",s); @@ -234,7 +423,7 @@ static int Columns_newindex(lua_State *L) { if( g_str_equal(cn->name,colname) ) { if (check_col(cols, cn->id)) col_set_str(cols, cn->id, text); - return 1; + return 0; } } @@ -246,7 +435,14 @@ static int Columns_index(lua_State *L) { const struct col_names_t* cn; const char* colname; - if (!cols) return 0; + if (!cols) { + Column c = g_malloc(sizeof(struct _eth_col_info)); + c->cinfo = NULL; + c->col = 0; + + pushColumn(L,c); + return 1; + } colname = luaL_checkstring(L,2); @@ -257,26 +453,26 @@ static int Columns_index(lua_State *L) { Column c = g_malloc(sizeof(struct _eth_col_info)); c->cinfo = cols; c->col = col_name_to_id(colname); - + pushColumn(L,c); - return 0; + return 1; } } - + return 0; } static const luaL_reg Columns_meta[] = { {"__tostring", Columns_tostring }, - {"__newindex", Columns_index }, - {"__index", Columns_newindex }, + {"__newindex", Columns_newindex }, + {"__index", Columns_index}, {0,0} }; int Columns_register(lua_State *L) { - luaL_newmetatable(L, COLUMN); + luaL_newmetatable(L, COLUMNS); luaL_openlib(L, NULL, Columns_meta, 0); return 1; @@ -295,8 +491,19 @@ static int Pinfo_tostring(lua_State *L) { lua_pushstring(L,"a Pinfo"); return 1; #define PINFO_GET_STRING(name,val) static int name(lua_State *L) { \ Pinfo pinfo = checkPinfo(L,1); \ + const gchar* value; \ if (!pinfo) return 0; \ - if (val) lua_pushstring(L,(const char*)(val)); else lua_pushnil(L); \ + value = val; \ + if (value) lua_pushstring(L,(const char*)(value)); else lua_pushnil(L); \ + return 1; \ +} + +#define PINFO_GET_ADDRESS(name,role) static int name(lua_State *L) { \ + Pinfo pinfo = checkPinfo(L,1); \ + Address addr = g_malloc(sizeof(address)); \ + if (!pinfo) return 0; \ + COPY_ADDRESS(addr, &(pinfo->role)); \ + pushAddress(L,addr); \ return 1; \ } @@ -306,59 +513,231 @@ PINFO_GET_NUMBER(Pinfo_caplen,pinfo->fd->cap_len); PINFO_GET_NUMBER(Pinfo_abs_ts,(((double)pinfo->fd->abs_ts.secs) + (((double)pinfo->fd->abs_ts.nsecs) / 1000000000.0) )); PINFO_GET_NUMBER(Pinfo_rel_ts,(((double)pinfo->fd->rel_ts.secs) + (((double)pinfo->fd->rel_ts.nsecs) / 1000000000.0) )); PINFO_GET_NUMBER(Pinfo_delta_ts,(((double)pinfo->fd->del_ts.secs) + (((double)pinfo->fd->del_ts.nsecs) / 1000000000.0) )); -PINFO_GET_NUMBER(Pinfo_visited,pinfo->fd->flags.visited); PINFO_GET_NUMBER(Pinfo_ipproto,pinfo->ipproto); PINFO_GET_NUMBER(Pinfo_circuit_id,pinfo->circuit_id); PINFO_GET_NUMBER(Pinfo_ptype,pinfo->ptype); -PINFO_GET_NUMBER(Pinfo_match_port,pinfo->match_port); +PINFO_GET_NUMBER(Pinfo_src_port,pinfo->srcport); +PINFO_GET_NUMBER(Pinfo_dst_port,pinfo->destport); -PINFO_GET_STRING(Pinfo_src,address_to_str(&(pinfo->src))); -PINFO_GET_STRING(Pinfo_dst,address_to_str(&(pinfo->dst))); -PINFO_GET_STRING(Pinfo_net_src,address_to_str(&(pinfo->net_src))); -PINFO_GET_STRING(Pinfo_net_dst,address_to_str(&(pinfo->net_dst))); -PINFO_GET_STRING(Pinfo_dl_src,address_to_str(&(pinfo->dl_src))); -PINFO_GET_STRING(Pinfo_dl_dst,address_to_str(&(pinfo->dl_dst))); -PINFO_GET_STRING(Pinfo_match_string,pinfo->match_string); PINFO_GET_STRING(Pinfo_curr_proto,pinfo->current_proto); -static int Pinfo_columns(lua_State *L) { +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); + +static int Pinfo_visited(lua_State *L) { Pinfo pinfo = checkPinfo(L,1); if (!pinfo) return 0; - pushColumns(L,pinfo->cinfo); + lua_pushboolean(L,pinfo->fd->flags.visited); return 1; } -static const luaL_reg Pinfo_methods[] = { - {"number", Pinfo_number }, - {"len", Pinfo_len }, - {"caplen", Pinfo_caplen }, - {"abs_ts",Pinfo_abs_ts }, - {"rel_ts",Pinfo_rel_ts }, - {"delta_ts",Pinfo_delta_ts }, - {"visited",Pinfo_visited }, - {"src_address", Pinfo_src }, - {"dst_address", Pinfo_dst }, - {"dl_src", Pinfo_dl_src }, - {"dl_dst", Pinfo_dl_dst }, - {"net_src", Pinfo_net_src }, - {"net_dst", Pinfo_net_dst }, - {"ipproto", Pinfo_ipproto }, - {"circuit_id", Pinfo_circuit_id }, - {"ptype", Pinfo_ptype }, - {"match_port", Pinfo_match_port }, - {"match_string", Pinfo_match_string }, - {"curr_proto", Pinfo_curr_proto }, - {"col", Pinfo_columns }, - {0,0} + +static int Pinfo_match(lua_State *L) { + Pinfo pinfo = checkPinfo(L,1); + + if (!pinfo) return 0; + + if (pinfo->match_string) { + lua_pushstring(L,pinfo->match_string); + } else { + lua_pushnumber(L,(lua_Number)(pinfo->match_port)); + } + + return 1; +} + +static int Pinfo_columns(lua_State *L) { + Pinfo pinfo = checkPinfo(L,1); + const gchar* colname = luaL_optstring(L,2,NULL); + + if (!colname) { + pushColumns(L,pinfo->cinfo); + } else { + lua_settop(L,0); + pushColumns(L,pinfo->cinfo); + lua_pushstring(L,colname); + return Columns_index(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_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; +} + +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; + } + + switch(pt) { + case PARAM_ADDR_SRC: + to = &(pinfo->src); + break; + case PARAM_ADDR_DST: + to = &(pinfo->src); + break; + case PARAM_ADDR_DL_SRC: + to = &(pinfo->src); + break; + case PARAM_ADDR_DL_DST: + to = &(pinfo->src); + break; + case PARAM_ADDR_NET_SRC: + to = &(pinfo->src); + break; + case PARAM_ADDR_NET_DST: + to = &(pinfo->src); + break; + default: + g_assert(!"BUG: A bad parameter"); + } + + COPY_ADDRESS(to,from); + return 0; +} + +int Pinfo_set_int(lua_State* L, packet_info* pinfo, pinfo_param_type_t pt) { + guint v = luaL_checkint(L,1); + + switch(pt) { + case PARAM_PORT_SRC: + pinfo->srcport = v; + return 0; + case PARAM_PORT_DST: + pinfo->destport = v; + return 0; + case PARAM_CIRCUIT_ID: + pinfo->circuit_id = 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 const pinfo_method_t Pinfo_methods[] = { + {"number", Pinfo_number, pushnil_param, PARAM_NONE}, + {"len", Pinfo_len, pushnil_param, PARAM_NONE }, + {"caplen", Pinfo_caplen, pushnil_param, PARAM_NONE }, + {"abs_ts",Pinfo_abs_ts, pushnil_param, PARAM_NONE }, + {"rel_ts",Pinfo_rel_ts, pushnil_param, PARAM_NONE }, + {"delta_ts",Pinfo_delta_ts, pushnil_param, PARAM_NONE }, + {"visited",Pinfo_visited, pushnil_param, PARAM_NONE }, + {"src", Pinfo_src, Pinfo_set_addr, PARAM_ADDR_SRC }, + {"dst", Pinfo_dst, Pinfo_set_addr, PARAM_ADDR_DST }, + {"dl_src", Pinfo_dl_src, Pinfo_set_addr, PARAM_ADDR_DL_SRC }, + {"dl_dst", Pinfo_dl_dst, Pinfo_set_addr, PARAM_ADDR_DL_DST }, + {"net_src", Pinfo_net_src, Pinfo_set_addr, PARAM_ADDR_NET_SRC }, + {"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 }, + {"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 }, + {"match", Pinfo_match, pushnil_param, PARAM_NONE }, + {"curr_proto", Pinfo_curr_proto, pushnil_param, PARAM_NONE }, + {"cols", Pinfo_columns, 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; + } + + 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; + } + + for (curr = Pinfo_methods ; curr->name ; curr++) { + if (g_str_equal(curr->name,name)) { + method = curr->set; + param_type = curr->param; + break; + } + } + + lua_pop(L,1); + lua_pop(L,1); + return method(L,pinfo,param_type); +} + static const luaL_reg Pinfo_meta[] = { + {"__index", Pinfo_index}, + {"__setindex",Pinfo_setindex}, {"__tostring", Pinfo_tostring}, {0, 0} }; int Pinfo_register(lua_State* L) { + luaL_newmetatable(L, PINFO); + luaL_openlib(L, NULL, Pinfo_meta, 0); +/* luaL_openlib(L, PINFO, Pinfo_methods, 0); luaL_newmetatable(L, PINFO); luaL_openlib(L, 0, Pinfo_meta, 0); @@ -369,7 +748,7 @@ int Pinfo_register(lua_State* L) { lua_pushvalue(L, -3); lua_rawset(L, -3); lua_pop(L, 1); - + */ return 1; }; diff --git a/plugins/lua/lua_proto.c b/plugins/lua/lua_proto.c index 332d34051b..596038b7a0 100644 --- a/plugins/lua/lua_proto.c +++ b/plugins/lua/lua_proto.c @@ -31,9 +31,12 @@ LUA_CLASS_DEFINE(Proto,PROTO,if (! *p) luaL_error(L,"null Proto")); LUA_CLASS_DEFINE(ProtoField,PROTO_FIELD,if (! *p) luaL_error(L,"null ProtoField")); LUA_CLASS_DEFINE(ProtoFieldArray,PROTO_FIELD_ARRAY,if (! *p) luaL_error(L,"null ProtoFieldArray")); -LUA_CLASS_DEFINE(Ett,ETT,NOP); -LUA_CLASS_DEFINE(EttArray,ETT_ARRAY,if (! *p) luaL_error(L,"null EttArray")); +LUA_CLASS_DEFINE(SubTreeType,SUB_TREE_TYPE,NOP); +LUA_CLASS_DEFINE(SubTreeTypeArray,SUB_TREE_TYPE_ARRAY,if (! *p) luaL_error(L,"null SubTreeTypeArray")); LUA_CLASS_DEFINE(ValueString,VALUE_STRING,NOP); +LUA_CLASS_DEFINE(Dissector,DISSECTOR,NOP); +LUA_CLASS_DEFINE(DissectorTable,DISSECTOR_TABLE,NOP); + /* * ProtoField class @@ -421,21 +424,21 @@ int ProtoFieldArray_register(lua_State* L) { /* - * Ett class + * SubTreeType class */ -static int Ett_new(lua_State* L) { - Ett e = g_malloc(sizeof(int)); +static int SubTreeType_new(lua_State* L) { + SubTreeType e = g_malloc(sizeof(int)); *e = -2; - pushEtt(L,e); + pushSubTreeType(L,e); return 1; } -static int Ett_tostring(lua_State* L) { - Ett e = checkEtt(L,1); - gchar* s = g_strdup_printf("Ett: %i",*e); +static int SubTreeType_tostring(lua_State* L) { + SubTreeType e = checkSubTreeType(L,1); + gchar* s = g_strdup_printf("SubTreeType: %i",*e); lua_pushstring(L,s); g_free(s); @@ -444,20 +447,20 @@ static int Ett_tostring(lua_State* L) { } -static const luaL_reg Ett_methods[] = { - {"new", Ett_new}, +static const luaL_reg SubTreeType_methods[] = { + {"new", SubTreeType_new}, {0,0} }; -static const luaL_reg Ett_meta[] = { - {"__tostring", Ett_tostring}, +static const luaL_reg SubTreeType_meta[] = { + {"__tostring", SubTreeType_tostring}, {0, 0} }; -int Ett_register(lua_State* L) { - luaL_openlib(L, ETT, Ett_methods, 0); - luaL_newmetatable(L, ETT); - luaL_openlib(L, 0, Ett_meta, 0); +int SubTreeType_register(lua_State* L) { + luaL_openlib(L, SUB_TREE_TYPE, SubTreeType_methods, 0); + luaL_newmetatable(L, SUB_TREE_TYPE); + luaL_openlib(L, 0, SubTreeType_meta, 0); lua_pushliteral(L, "__index"); lua_pushvalue(L, -3); lua_rawset(L, -3); @@ -474,16 +477,16 @@ int Ett_register(lua_State* L) { /* - * EttArray class + * SubTreeTypeArray class */ -static int EttArray_new(lua_State* L) { - EttArray ea = g_array_new(TRUE,TRUE,sizeof(gint*)); +static int SubTreeTypeArray_new(lua_State* L) { + SubTreeTypeArray ea = g_array_new(TRUE,TRUE,sizeof(gint*)); guint i; guint num_args = lua_gettop(L); for (i = 1; i <= num_args; i++) { - Ett e = checkEtt(L,i); + SubTreeType e = checkSubTreeType(L,i); if(*e != -2) { luaL_argerror(L, i, "SubTree has already been added to an array"); @@ -495,18 +498,18 @@ static int EttArray_new(lua_State* L) { g_array_append_val(ea,e); } - pushEttArray(L,ea); + pushSubTreeTypeArray(L,ea); return 1; } -static int EttArray_add(lua_State* L) { - EttArray ea = checkEttArray(L,1); +static int SubTreeTypeArray_add(lua_State* L) { + SubTreeTypeArray ea = checkSubTreeTypeArray(L,1); guint i; guint num_args = lua_gettop(L); for (i = 2; i <= num_args; i++) { - Ett e = checkEtt(L,i); + SubTreeType e = checkSubTreeType(L,i); if(*e != -2) { luaL_argerror(L, i, "SubTree has already been added to an array"); return 0; @@ -520,9 +523,9 @@ static int EttArray_add(lua_State* L) { return 0; } -static int EttArray_tostring(lua_State* L) { - GString* s = g_string_new("EttArray:\n"); - EttArray ea = checkEttArray(L,1); +static int SubTreeTypeArray_tostring(lua_State* L) { + GString* s = g_string_new("SubTreeTypeArray:\n"); + SubTreeTypeArray ea = checkSubTreeTypeArray(L,1); unsigned i; for(i = 0; i< ea->len; i++) { @@ -536,8 +539,8 @@ static int EttArray_tostring(lua_State* L) { return 1; } -static int EttArray_register_to_ethereal(lua_State* L) { - EttArray ea = checkEttArray(L,1); +static int SubTreeTypeArray_register_to_ethereal(lua_State* L) { + SubTreeTypeArray ea = checkSubTreeTypeArray(L,1); if (!ea->len) { luaL_argerror(L,1,"empty array"); @@ -554,8 +557,8 @@ static int EttArray_register_to_ethereal(lua_State* L) { return 0; } -static int EttArray_gc(lua_State* L) { - EttArray ea = checkEttArray(L,1); +static int SubTreeTypeArray_gc(lua_State* L) { + SubTreeTypeArray ea = checkSubTreeTypeArray(L,1); g_array_free(ea,FALSE); @@ -563,23 +566,23 @@ static int EttArray_gc(lua_State* L) { } -static const luaL_reg EttArray_methods[] = { - {"new", EttArray_new}, - {"add", EttArray_add}, - {"register", EttArray_register_to_ethereal}, +static const luaL_reg SubTreeTypeArray_methods[] = { + {"new", SubTreeTypeArray_new}, + {"add", SubTreeTypeArray_add}, + {"register", SubTreeTypeArray_register_to_ethereal}, {0,0} }; -static const luaL_reg EttArray_meta[] = { - {"__gc", EttArray_gc}, - {"__tostring", EttArray_tostring}, +static const luaL_reg SubTreeTypeArray_meta[] = { + {"__gc", SubTreeTypeArray_gc}, + {"__tostring", SubTreeTypeArray_tostring}, {0, 0} }; -int EttArray_register(lua_State* L) { - luaL_openlib(L, ETT_ARRAY, EttArray_methods, 0); - luaL_newmetatable(L, ETT_ARRAY); - luaL_openlib(L, 0, EttArray_meta, 0); +int SubTreeTypeArray_register(lua_State* L) { + luaL_openlib(L, SUB_TREE_TYPE_ARRAY, SubTreeTypeArray_methods, 0); + luaL_newmetatable(L, SUB_TREE_TYPE_ARRAY); + luaL_openlib(L, 0, SubTreeTypeArray_meta, 0); lua_pushliteral(L, "__index"); lua_pushvalue(L, -3); lua_rawset(L, -3); @@ -884,10 +887,6 @@ int Proto_register(lua_State* L) { return 1; } -LUA_CLASS_DEFINE(Dissector,DISSECTOR,NOP); -LUA_CLASS_DEFINE(DissectorTable,DISSECTOR_TABLE,NOP); - - /* * Dissector class */ @@ -914,7 +913,7 @@ static int Dissector_call(lua_State* L) { Dissector d = checkDissector(L,1); Tvb tvb = checkTvb(L,2); Pinfo pinfo = checkPinfo(L,3); - Tree tree = checkTree(L,4); + ProtoTree tree = checkProtoTree(L,4); if (! ( d && tvb && pinfo) ) return 0; @@ -930,7 +929,6 @@ static int Dissector_tostring(lua_State* L) { return 1; } - static const luaL_reg Dissector_methods[] = { {"get", Dissector_get }, {"call", Dissector_call }, @@ -958,10 +956,6 @@ int Dissector_register(lua_State* L) { }; - - - - /* * DissectorTable class */ @@ -1046,7 +1040,7 @@ static int DissectorTable_try (lua_State *L) { DissectorTable dt = checkDissectorTable(L,1); Tvb tvb = checkTvb(L,3); Pinfo pinfo = checkPinfo(L,4); - Tree tree = checkTree(L,5); + ProtoTree tree = checkProtoTree(L,5); ftenum_t type; if (! (dt && tvb && pinfo && tree) ) return 0; @@ -1229,7 +1223,7 @@ static const luaL_reg ValueString_meta[] = { }; -extern int ValueString_register(lua_State* L) { +int ValueString_register(lua_State* L) { luaL_openlib(L, VALUE_STRING, ValueString_methods, 0); luaL_newmetatable(L, VALUE_STRING); luaL_openlib(L, 0, ValueString_meta, 0); diff --git a/plugins/lua/lua_tap.c b/plugins/lua/lua_tap.c index 14b9c97486..54aa9a1c30 100644 --- a/plugins/lua/lua_tap.c +++ b/plugins/lua/lua_tap.c @@ -29,11 +29,11 @@ #include "packet-lua.h" LUA_CLASS_DEFINE(Tap,TAP,NOP); -LUA_CLASS_DEFINE(Interesting,INTERESTING,NOP); +LUA_CLASS_DEFINE(Field,FIELD,NOP); -static int Interesting_get (lua_State *L) { +static int Field_get (lua_State *L) { const gchar* name = luaL_checkstring(L,1); - Interesting i; + Field i; if (!name) return 0; @@ -44,12 +44,12 @@ static int Interesting_get (lua_State *L) { return 0; } - pushInteresting(L,i); + pushField(L,i); return 1; } -static int Interesting_fetch (lua_State* L) { - Interesting in = checkInteresting(L,1); +static int Field_fetch (lua_State* L) { + Field in = checkField(L,1); int items_found = 0; for (;in;in = in->same_name_next) { @@ -103,28 +103,28 @@ static int Interesting_fetch (lua_State* L) { } -static int Interesting_tostring (lua_State* L) { - Interesting in = checkInteresting(L,1); +static int Field_tostring (lua_State* L) { + Field in = checkField(L,1); - lua_pushfstring(L,"Interesting: %s",in->abbrev); + lua_pushfstring(L,"Field: %s",in->abbrev); return 1; } -static const luaL_reg Interesting_methods[] = { - {"get", Interesting_get}, - {"fetch", Interesting_fetch }, +static const luaL_reg Field_methods[] = { + {"get", Field_get}, + {"fetch", Field_fetch }, {0,0} }; -static const luaL_reg Interesting_meta[] = { - {"__tostring", Interesting_tostring}, +static const luaL_reg Field_meta[] = { + {"__tostring", Field_tostring}, {0, 0} }; -int Interesting_register(lua_State* L) { - luaL_openlib(L, INTERESTING, Interesting_methods, 0); - luaL_newmetatable(L, INTERESTING); - luaL_openlib(L, 0, Interesting_meta, 0); +int Field_register(lua_State* L) { + luaL_openlib(L, FIELD, Field_methods, 0); + luaL_newmetatable(L, FIELD); + luaL_openlib(L, 0, Field_meta, 0); lua_pushliteral(L, "__index"); lua_pushvalue(L, -3); lua_rawset(L, -3); @@ -160,7 +160,7 @@ static int Tap_new(lua_State* L) { static int Tap_add(lua_State* L) { Tap tap = checkTap(L,1); - Interesting in = checkInteresting(L,2); + Field in = checkField(L,2); if (!(tap && in)) return 0; @@ -217,7 +217,7 @@ static int Tap_register_to_ethereal(lua_State*L) { ins = tap->interesting_fields; for (i=0; i < ins->len; i++) { - Interesting in = g_ptr_array_index(ins,i); + Field in = g_ptr_array_index(ins,i); g_string_sprintfa(filter_s," ||%s",in->abbrev); } diff --git a/plugins/lua/lua_tree.c b/plugins/lua/lua_tree.c index 3811da0a7e..98d68ca841 100644 --- a/plugins/lua/lua_tree.c +++ b/plugins/lua/lua_tree.c @@ -28,12 +28,12 @@ #include "packet-lua.h" -LUA_CLASS_DEFINE(Tree,TREE,NOP); -LUA_CLASS_DEFINE(Item,ITEM,NOP); +LUA_CLASS_DEFINE(ProtoTree,PROTO_TREE,NOP); +LUA_CLASS_DEFINE(ProtoItem,ITEM,NOP); -/* Tree class */ +/* ProtoTree class */ -static int Tree_add_item_any(lua_State *L, gboolean little_endian) { +static int ProtoTree_add_item_any(lua_State *L, gboolean little_endian) { /* called with: tree,field,tvb,offset,len,datum @@ -41,15 +41,15 @@ static int Tree_add_item_any(lua_State *L, gboolean little_endian) { tree,tvb,offset,len,text tree,tvb,text */ - Tree tree = checkTree(L,1); + ProtoTree tree = checkProtoTree(L,1); ProtoField field; - Item item; + ProtoItem item; Tvb tvb; int offset; int len; if (!tree) { - pushItem(L,NULL); + pushProtoItem(L,NULL); return 1; } @@ -125,49 +125,49 @@ static int Tree_add_item_any(lua_State *L, gboolean little_endian) { return 0; } - pushItem(L,item); + pushProtoItem(L,item); return 1; } -static int Tree_add_item(lua_State *L) { return Tree_add_item_any(L,FALSE); } -static int Tree_add_item_le(lua_State *L) { return Tree_add_item_any(L,TRUE); } +static int ProtoTree_add_item(lua_State *L) { return ProtoTree_add_item_any(L,FALSE); } +static int ProtoTree_add_item_le(lua_State *L) { return ProtoTree_add_item_any(L,TRUE); } -static int Tree_tostring(lua_State *L) { - Tree tree = checkTree(L,1); - lua_pushstring(L,ep_strdup_printf("Tree %p",tree)); +static int ProtoTree_tostring(lua_State *L) { + ProtoTree tree = checkProtoTree(L,1); + lua_pushstring(L,ep_strdup_printf("ProtoTree %p",tree)); return 1; } -static int Tree_get_parent(lua_State *L) { - Tree tree = checkTree(L,1); +static int ProtoTree_get_parent(lua_State *L) { + ProtoTree tree = checkProtoTree(L,1); proto_item* item = NULL; if (tree) { item = proto_tree_get_parent(tree); } - pushItem(L,item); + pushProtoItem(L,item); return 1; } -static const luaL_reg Tree_methods[] = { - {"add_item", Tree_add_item}, - {"add_item_le", Tree_add_item_le}, - {"get_parent", Tree_get_parent}, +static const luaL_reg ProtoTree_methods[] = { + {"add_item", ProtoTree_add_item}, + {"add_item_le", ProtoTree_add_item_le}, + {"get_parent", ProtoTree_get_parent}, {0, 0} }; -static const luaL_reg Tree_meta[] = { - {"__tostring", Tree_tostring}, +static const luaL_reg ProtoTree_meta[] = { + {"__tostring", ProtoTree_tostring}, {0, 0} }; -int Tree_register(lua_State* L) { - luaL_openlib(L, TREE, Tree_methods, 0); - luaL_newmetatable(L, TREE); - luaL_openlib(L, 0, Tree_meta, 0); +int ProtoTree_register(lua_State* L) { + luaL_openlib(L, PROTO_TREE, ProtoTree_methods, 0); + luaL_newmetatable(L, PROTO_TREE); + luaL_openlib(L, 0, ProtoTree_meta, 0); lua_pushliteral(L, "__index"); lua_pushvalue(L, -3); lua_rawset(L, -3); @@ -179,20 +179,20 @@ int Tree_register(lua_State* L) { return 1; } -/* Item class */ -static int Item_tostring(lua_State *L) { - Item item = checkItem(L,1); - lua_pushstring(L,ep_strdup_printf("Item %p",item)); +/* ProtoItem class */ +static int ProtoItem_tostring(lua_State *L) { + ProtoItem item = checkProtoItem(L,1); + lua_pushstring(L,ep_strdup_printf("ProtoItem %p",item)); return 1; } -static int Item_add_subtree(lua_State *L) { - Item item = checkItem(L,1); - Ett ett; - Tree tree = NULL; +static int ProtoItem_add_subtree(lua_State *L) { + ProtoItem item = checkProtoItem(L,1); + SubTreeType ett; + ProtoTree tree = NULL; if (item) { - ett = checkEtt(L,2); + ett = checkSubTreeType(L,2); if (ett && *ett >= 0) { tree = proto_item_add_subtree(item,*ett); @@ -201,12 +201,12 @@ static int Item_add_subtree(lua_State *L) { } } - pushTree(L,tree); + pushProtoTree(L,tree); return 1; } -static int Item_set_text(lua_State *L) { - Item item = checkItem(L,1); +static int ProtoItem_set_text(lua_State *L) { + ProtoItem item = checkProtoItem(L,1); if (!item) { const gchar* s = luaL_checkstring(L,2); @@ -216,8 +216,8 @@ static int Item_set_text(lua_State *L) { return 0; } -static int Item_append_text(lua_State *L) { - Item item = checkItem(L,1); +static int ProtoItem_append_text(lua_State *L) { + ProtoItem item = checkProtoItem(L,1); const gchar* s; if (item) { @@ -227,8 +227,8 @@ static int Item_append_text(lua_State *L) { return 0; } -static int Item_set_len(lua_State *L) { - Item item = checkItem(L,1); +static int ProtoItem_set_len(lua_State *L) { + ProtoItem item = checkProtoItem(L,1); int len; if (item) { @@ -284,8 +284,8 @@ static const gchar* expert_to_str(int val) { } #endif -static int Item_set_expert_flags(lua_State *L) { - Item item = checkItem(L,1); +static int ProtoItem_set_expert_flags(lua_State *L) { + ProtoItem item = checkProtoItem(L,1); int group; int severity; @@ -302,8 +302,8 @@ static int Item_set_expert_flags(lua_State *L) { } -static int Item_set_generated(lua_State *L) { - Item item = checkItem(L,1); +static int ProtoItem_set_generated(lua_State *L) { + ProtoItem item = checkProtoItem(L,1); if (item) { PROTO_ITEM_SET_GENERATED(item); } @@ -311,38 +311,38 @@ static int Item_set_generated(lua_State *L) { } -static int Item_set_hidden(lua_State *L) { - Item item = checkItem(L,1); +static int ProtoItem_set_hidden(lua_State *L) { + ProtoItem item = checkProtoItem(L,1); if (item) { PROTO_ITEM_SET_HIDDEN(item); } return 0; } -static const luaL_reg Item_methods[] = { - {"add_subtree", Item_add_subtree}, - {"set_text", Item_set_text}, - {"append_text", Item_append_text}, - {"set_len", Item_set_len}, - {"set_expert_flags", Item_set_expert_flags}, - {"set_generated", Item_set_generated}, - {"set_hidden", Item_set_hidden}, +static const luaL_reg ProtoItem_methods[] = { + {"add_subtree", ProtoItem_add_subtree}, + {"set_text", ProtoItem_set_text}, + {"append_text", ProtoItem_append_text}, + {"set_len", ProtoItem_set_len}, + {"set_expert_flags", ProtoItem_set_expert_flags}, + {"set_generated", ProtoItem_set_generated}, + {"set_hidden", ProtoItem_set_hidden}, {0, 0} }; -static const luaL_reg Item_meta[] = { - {"__tostring", Item_tostring}, +static const luaL_reg ProtoItem_meta[] = { + {"__tostring", ProtoItem_tostring}, {0, 0} }; -int Item_register(lua_State *L) { +int ProtoItem_register(lua_State *L) { const struct _expert_severity* s; - luaL_openlib(L, ITEM, Item_methods, 0); + luaL_openlib(L, ITEM, ProtoItem_methods, 0); luaL_newmetatable(L, ITEM); - luaL_openlib(L, 0, Item_meta, 0); + luaL_openlib(L, 0, ProtoItem_meta, 0); lua_pushliteral(L, "__index"); lua_pushvalue(L, -3); lua_rawset(L, -3); diff --git a/plugins/lua/packet-lua.c b/plugins/lua/packet-lua.c index 4542c2d6cb..9555c4df37 100644 --- a/plugins/lua/packet-lua.c +++ b/plugins/lua/packet-lua.c @@ -28,11 +28,14 @@ #include "packet-lua.h" static lua_State* L = NULL; +packet_info* lua_pinfo; +proto_tree* lua_tree; +dissector_handle_t lua_data_handle; /* ethereal uses lua */ -extern int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const void *data _U_) { +int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const void *data _U_) { Tap tap = tapdata; lua_pushstring(L, "_ethereal_pinfo"); @@ -67,7 +70,7 @@ void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) { lua_settable(L, LUA_GLOBALSINDEX); lua_pushstring(L, "_ethereal_tree"); - pushTree(L, tree); + pushProtoTree(L, tree); lua_settable(L, LUA_GLOBALSINDEX); lua_pinfo = pinfo; @@ -98,26 +101,6 @@ static const char *getF(lua_State *L _U_, void *ud, size_t *size) return (*size>0) ? buff : NULL; } -extern void lua_functions_defined_but_unused(void) { - toValueString(L,1); - toProtoField(L,1); - toProtoFieldArray(L,1); - toEtt(L,1); - toEttArray(L,1); - toProto(L,1); - toByteArray(L,1); - toTvb(L,1); - toColumn(L,1); - toPinfo(L,1); - toTree(L,1); - toItem(L,1); - toDissector(L,1); - toDissectorTable(L,1); - toInteresting(L,1); - toTap(L,1); - toColumns(L,1); -} - void proto_register_lua(void) { FILE* file; @@ -145,20 +128,22 @@ void proto_register_lua(void) ValueString_register(L); ProtoField_register(L); ProtoFieldArray_register(L); - Ett_register(L); - EttArray_register(L); + SubTreeType_register(L); + SubTreeTypeArray_register(L); ByteArray_register(L); Tvb_register(L); Proto_register(L); Column_register(L); Pinfo_register(L); - Tree_register(L); - Item_register(L); + ProtoTree_register(L); + ProtoItem_register(L); Dissector_register(L); DissectorTable_register(L); - Interesting_register(L); + Field_register(L); Columns_register(L); Tap_register(L); + Address_register(L); + lua_pushstring(L, "handoff_routines"); lua_newtable (L); lua_settable(L, LUA_GLOBALSINDEX); diff --git a/plugins/lua/packet-lua.h b/plugins/lua/packet-lua.h index a9f1a072a9..c4b6e14a56 100644 --- a/plugins/lua/packet-lua.h +++ b/plugins/lua/packet-lua.h @@ -95,14 +95,14 @@ typedef GArray* ValueString; #define PROTO_FIELD "ProtoField" typedef struct _eth_field_t* ProtoField; -#define PROTO_FIELD_ARRAY "ProtoFieldArr" +#define PROTO_FIELD_ARRAY "ProtoFieldArray" typedef GArray* ProtoFieldArray; -#define ETT "SubTreeType" -typedef int* Ett; +#define SUB_TREE_TYPE "SubTreeType" +typedef int* SubTreeType; -#define ETT_ARRAY "SubTreeTypeArr" -typedef GArray* EttArray; +#define SUB_TREE_TYPE_ARRAY "SubTreeTypeArray" +typedef GArray* SubTreeTypeArray; #define PROTO "Proto" typedef struct _eth_proto_t* Proto; @@ -134,17 +134,17 @@ typedef column_info* Columns; #define PINFO "Pinfo" typedef packet_info* Pinfo; -#define TREE "Tree" -typedef proto_tree* Tree; +#define PROTO_TREE "ProtoTree" +typedef proto_tree* ProtoTree; -#define ITEM "Item" -typedef proto_item* Item; +#define ITEM "ProtoItem" +typedef proto_item* ProtoItem; #define ADDRESS "Address" typedef address* Address; -#define INTERESTING "Interesting" -typedef header_field_info* Interesting; +#define FIELD "Field" +typedef header_field_info* Field; #define TAP "Tap" typedef struct _eth_tap { @@ -186,22 +186,23 @@ extern C* push##C(lua_State* L, C v); \ extern int C##_register(lua_State* L); LUA_CLASS_DECLARE(Tap,TAP); -LUA_CLASS_DECLARE(Interesting,INTERESTING); +LUA_CLASS_DECLARE(Field,FIELD); LUA_CLASS_DECLARE(ValueString,VALUE_STRING); LUA_CLASS_DECLARE(ProtoField,PROTO_FIELD); LUA_CLASS_DECLARE(ProtoFieldArray,PROTO_FIELD_ARRAY); -LUA_CLASS_DECLARE(Ett,ETT); -LUA_CLASS_DECLARE(EttArray,ETT_ARRAY); +LUA_CLASS_DECLARE(SubTreeType,SUB_TREE_TYPE); +LUA_CLASS_DECLARE(SubTreeTypeArray,SUB_TREE_TYPE_ARRAY); LUA_CLASS_DECLARE(Proto,PROTO); LUA_CLASS_DECLARE(ByteArray,BYTE_ARRAY); LUA_CLASS_DECLARE(Tvb,TVB); LUA_CLASS_DECLARE(Column,COLUMN); LUA_CLASS_DECLARE(Columns,COLUMNS); LUA_CLASS_DECLARE(Pinfo,PINFO); -LUA_CLASS_DECLARE(Tree,TREE); -LUA_CLASS_DECLARE(Item,ITEM); +LUA_CLASS_DECLARE(ProtoTree,TREE); +LUA_CLASS_DECLARE(ProtoItem,ITEM); LUA_CLASS_DECLARE(Dissector,DISSECTOR); LUA_CLASS_DECLARE(DissectorTable,DISSECTOR_TABLE); +LUA_CLASS_DECLARE(Address,ADDRESS); extern void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree); extern int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const void *data _U_); |