* lua_pinfo.c
* Address' gt, ge, eq, le and lt operators * lua_proto.c * DissectorTable:remove and DissectorTable:add - can take either Proto or Dissector as third argument * lua_tree.c * make sure we have a lua_etts array on which to add etts * ProtoItem:add_subtree() if no ett is given don't fail use the default one. svn path=/trunk/; revision=17111
This commit is contained in:
parent
31aa31f626
commit
ef78577292
|
@ -196,9 +196,79 @@ static int Address_gc(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int Address_gt(lua_State* L) {
|
||||
Address addr1 = checkAddress(L,1);
|
||||
Address addr2 = checkAddress(L,2);
|
||||
gboolean result = FALSE;
|
||||
|
||||
if (CMP_ADDRESS(addr1, addr2) > 0)
|
||||
result = TRUE;
|
||||
|
||||
lua_pushboolean(L,result);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int 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;
|
||||
}
|
||||
|
||||
static int Address_eq(lua_State* L) {
|
||||
Address addr1 = checkAddress(L,1);
|
||||
Address addr2 = checkAddress(L,2);
|
||||
gboolean result = FALSE;
|
||||
|
||||
if (ADDRESSES_EQUAL(addr1, addr2))
|
||||
result = TRUE;
|
||||
|
||||
lua_pushboolean(L,result);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Address_le(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;
|
||||
}
|
||||
|
||||
static int Address_lt(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;
|
||||
}
|
||||
|
||||
static const luaL_reg Address_meta[] = {
|
||||
{"__gc", Address_gc },
|
||||
{"__tostring", Address_tostring },
|
||||
{"__gt",Address_gt},
|
||||
{"__ge",Address_ge},
|
||||
{"__eq",Address_eq},
|
||||
{"__le",Address_le},
|
||||
{"__lt",Address_lt},
|
||||
{0,0}
|
||||
};
|
||||
|
||||
|
|
|
@ -1133,19 +1133,27 @@ static int DissectorTable_get (lua_State *L) {
|
|||
|
||||
static int DissectorTable_add (lua_State *L) {
|
||||
DissectorTable dt = checkDissectorTable(L,1);
|
||||
Proto p = checkProto(L,3);
|
||||
Proto p;
|
||||
ftenum_t type;
|
||||
|
||||
if (!(dt && p)) return 0;
|
||||
Dissector handle;
|
||||
|
||||
if (!dt) return 0;
|
||||
|
||||
if(( p = luaL_checkudata(L,3,PROTO) )) {
|
||||
handle = p->handle;
|
||||
} else if (! ( handle = luaL_checkudata(L,3,DISSECTOR) )) {
|
||||
luaL_argerror(L,3,"Must be either " PROTO " or " DISSECTOR );
|
||||
return 0;
|
||||
}
|
||||
|
||||
type = get_dissector_table_selector_type(dt->name);
|
||||
|
||||
if (type == FT_STRING) {
|
||||
gchar* pattern = g_strdup(luaL_checkstring(L,2));
|
||||
dissector_add_string(dt->name, pattern,p->handle);
|
||||
dissector_add_string(dt->name, pattern,handle);
|
||||
} else if ( type == FT_UINT32 || type == FT_UINT16 || type == FT_UINT8 || type == FT_UINT24 ) {
|
||||
int port = luaL_checkint(L, 2);
|
||||
dissector_add(dt->name, port, p->handle);
|
||||
dissector_add(dt->name, port, handle);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1153,19 +1161,27 @@ static int DissectorTable_add (lua_State *L) {
|
|||
|
||||
static int DissectorTable_remove (lua_State *L) {
|
||||
DissectorTable dt = checkDissectorTable(L,1);
|
||||
Proto p = checkProto(L,3);
|
||||
Proto p;
|
||||
ftenum_t type;
|
||||
Dissector handle;
|
||||
|
||||
if (!(dt && p)) return 0;
|
||||
if (!dt) return 0;
|
||||
|
||||
if(( p = luaL_checkudata(L,3,PROTO) )) {
|
||||
handle = p->handle;
|
||||
} else if (! ( handle = luaL_checkudata(L,3,DISSECTOR) )) {
|
||||
luaL_argerror(L,3,"Must be either " PROTO " or " DISSECTOR );
|
||||
return 0;
|
||||
}
|
||||
|
||||
type = get_dissector_table_selector_type(dt->name);
|
||||
|
||||
if (type == FT_STRING) {
|
||||
gchar* pattern = g_strdup(luaL_checkstring(L,2));
|
||||
dissector_delete_string(dt->name, pattern,p->handle);
|
||||
dissector_delete_string(dt->name, pattern,handle);
|
||||
} else if ( type == FT_UINT32 || type == FT_UINT16 || type == FT_UINT8 || type == FT_UINT24 ) {
|
||||
int port = luaL_checkint(L, 2);
|
||||
dissector_delete(dt->name, port, p->handle);
|
||||
dissector_delete(dt->name, port, handle);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -44,6 +44,10 @@ static gint lua_ett = -1;
|
|||
|
||||
void lua_register_subtrees(void) {
|
||||
gint* ettp = &lua_ett;
|
||||
|
||||
if (!lua_etts)
|
||||
lua_etts = g_array_new(FALSE,FALSE,sizeof(gint*));
|
||||
|
||||
g_array_append_val(lua_etts,ettp);
|
||||
|
||||
proto_register_subtree_array((gint**)lua_etts->data,lua_etts->len);
|
||||
|
@ -293,7 +297,7 @@ static int ProtoItem_add_subtree(lua_State *L) {
|
|||
ProtoTree tree = NULL;
|
||||
|
||||
if (item) {
|
||||
SubTree ett = checkSubTree(L,2);
|
||||
SubTree ett = luaL_checkudata(L,2,SUBTREE);
|
||||
|
||||
if (ett) {
|
||||
tree = proto_item_add_subtree(item,*ett);
|
||||
|
|
Loading…
Reference in New Issue