aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua/wslua_tvb.c
diff options
context:
space:
mode:
authorBalint Reczey <balint.reczey@ericsson.com>2008-10-31 18:14:47 +0000
committerBalint Reczey <balint.reczey@ericsson.com>2008-10-31 18:14:47 +0000
commit33294f830c1b63d7ecde922aee90d126dc00e461 (patch)
tree4e64b036928e095dc3980e47dc8b847defdf4bef /epan/wslua/wslua_tvb.c
parentb2185260af318dc4cdd15b120e1c234089db84b4 (diff)
Provide TvbRange:{offset|len}() instead of TvbRange.{offset|len}.
Write access to offset and len from Lua is gone, too. This fixes bug 2243. svn path=/trunk/; revision=26657
Diffstat (limited to 'epan/wslua/wslua_tvb.c')
-rw-r--r--epan/wslua/wslua_tvb.c108
1 files changed, 27 insertions, 81 deletions
diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c
index f81c2150d6..447c7d9e79 100644
--- a/epan/wslua/wslua_tvb.c
+++ b/epan/wslua/wslua_tvb.c
@@ -568,85 +568,6 @@ int Tvb_register(lua_State* L) {
return 1;
}
-/*
- * read access to tvbr's data
- */
-static int TvbRange_index(lua_State* L) {
- /* WSLUA_ATTRIBUTE TvbRange_tvb RO The Tvb from which this TvbRange was generated */
- /* WSLUA_ATTRIBUTE TvbRange_len RW The length (in octets) of this TvbRange */
- /* WSLUA_ATTRIBUTE TvbRange_offset RW The offset (in octets) of this TvbRange */
-
- TvbRange tvbr = checkTvbRange(L,1);
- Tvb tvb;
- const gchar* index = luaL_checkstring(L,2);
-
- if (!(tvbr && index && tvbr->tvb)) return 0;
- if (tvbr->tvb->expired) {
- luaL_error(L,"expired tvb");
- return 0;
- }
-
- if (g_str_equal(index,"offset")) {
- lua_pushnumber(L,(lua_Number)tvbr->offset);
- return 1;
- } else if (g_str_equal(index,"len")) {
- lua_pushnumber(L,(lua_Number)tvbr->len);
- return 1;
- } else if (g_str_equal(index,"tvb")) {
- tvb = g_malloc(sizeof(struct _wslua_tvb));
- tvb->ws_tvb = tvb_new_subset(tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len, tvbr->len);
- tvb->expired = FALSE;
- PUSH_TVB(L,tvbr->tvb);
- return 1;
- } else {
- luaL_error(L,"TvbRange has no `%s' attribute",index);
- }
-
- return 0;
-}
-
-/*
- * write access to tvbr's data
- */
-static int TvbRange_newindex(lua_State* L) {
- TvbRange tvbr = checkTvbRange(L,1);
- const gchar* index = luaL_checkstring(L,2);
-
- if (!(tvbr && !tvbr->tvb)) return 0;
- if (tvbr->tvb->expired) {
- luaL_error(L,"expired tvb");
- return 0;
- }
-
- if (g_str_equal(index,"offset")) {
- int offset = (int)lua_tonumber(L,3);
-
- if ( (guint)(tvbr->len + offset) > tvb_length(tvbr->tvb->ws_tvb)) {
- luaL_error(L,"out of bounds");
- return 0;
- } else {
- tvbr->offset = offset;
- PUSH_TVBRANGE(L,tvbr);
- return 1;
- }
- } else if (g_str_equal(index,"len")) {
- int len = (int)lua_tonumber(L,3);
-
- if ( (guint)(tvbr->offset + len) > tvb_length(tvbr->tvb->ws_tvb)) {
- luaL_error(L,"out of bounds");
- return 0;
- } else {
- tvbr->len = len;
- PUSH_TVBRANGE(L,tvbr);
- return 1;
- }
- } else {
- luaL_error(L,"cannot set `%s' attribute on TvbRange",index);
- return 0;
- }
-
- return 0;
-}
/*
* get a Blefuscuoan unsigned integer from a tvb
@@ -943,6 +864,31 @@ WSLUA_METHOD TvbRange_bytes(lua_State* L) {
WSLUA_RETURN(1); /* the ByteArray */
}
+WSLUA_METHOD TvbRange_len(lua_State* L) {
+ TvbRange tvbr = checkTvbRange(L,1);
+
+ if (!(tvbr && tvbr->tvb)) return 0;
+ if (tvbr->tvb->expired) {
+ luaL_error(L,"expired tvb");
+ return 0;
+ }
+ lua_pushnumber(L,(lua_Number)tvbr->len);
+ return 1;
+}
+
+WSLUA_METHOD TvbRange_offset(lua_State* L) {
+ TvbRange tvbr = checkTvbRange(L,1);
+
+ if (!(tvbr && tvbr->tvb)) return 0;
+ if (tvbr->tvb->expired) {
+ luaL_error(L,"expired tvb");
+ return 0;
+ }
+ lua_pushnumber(L,(lua_Number)tvbr->offset);
+ return 1;
+}
+
+
WSLUA_METAMETHOD TvbRange__tostring(lua_State* L) {
/* converts the TvbRange into a string. As the string gets truncated
you should use this only for debugging purposes
@@ -971,13 +917,13 @@ static const luaL_reg TvbRange_methods[] = {
{"le_ipv4", TvbRange_le_ipv4},
{"string", TvbRange_string},
{"bytes", TvbRange_bytes},
+ {"len", TvbRange_len},
+ {"offset", TvbRange_offset},
{"tvb", Tvb_tvb},
{ NULL, NULL }
};
static const luaL_reg TvbRange_meta[] = {
- {"__index", TvbRange_index},
- {"__newindex", TvbRange_newindex},
{"__tostring", TvbRange__tostring},
{ NULL, NULL }
};