static int TvbRange_uncompress(lua_State* L) { /* Obtain a uncompressed TvbRange from a TvbRange */ #define WSLUA_ARG_TvbRange_uncompress_NAME 2 /* The name to be given to the new data-source. */ TvbRange tvbr = checkTvbRange(L,1); const gchar* name = luaL_optstring(L,WSLUA_ARG_TvbRange_uncompress_NAME,"Uncompressed"); tvbuff_t *uncompr_tvb; if (!(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { luaL_error(L,"expired tvb"); return 0; } #ifdef HAVE_LIBZ uncompr_tvb = tvb_child_uncompress(tvbr->tvb->ws_tvb, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len); if (uncompr_tvb) { add_new_data_source (lua_pinfo, uncompr_tvb, name); if (push_TvbRange(L,uncompr_tvb,0,tvb_length(uncompr_tvb))) { WSLUA_RETURN(1); /* The TvbRange */ } } #else luaL_error(L,"Missing support for ZLIB"); #endif return 0; }
WSLUA_METHOD TvbRange_range(lua_State* L) { /* Creates a sub-TvbRange from this TvbRange. This is used also as the TvbRange:__call() metamethod. */ #define WSLUA_OPTARG_TvbRange_range_OFFSET 2 /* The offset (in octets) from the beginning of the TvbRange. Defaults to 0. */ #define WSLUA_OPTARG_TvbRange_range_LENGTH 3 /* The length (in octets) of the range. Defaults to until the end of the TvbRange. */ TvbRange tvbr = checkTvbRange(L,1); int offset = luaL_optint(L,WSLUA_OPTARG_TvbRange_range_OFFSET,0); int len; if (!(tvbr && tvbr->tvb)) return 0; len = luaL_optint(L,WSLUA_OPTARG_TvbRange_range_LENGTH,tvbr->len-offset); if (tvbr->tvb->expired) { luaL_error(L,"expired tvb"); return 0; } if (offset >= tvbr->len || (len + offset) > tvbr->len) { luaL_error(L,"Range is out of bounds"); return 0; } if (push_TvbRange(L,tvbr->tvb->ws_tvb,tvbr->offset+offset,len)) { WSLUA_RETURN(1); /* The TvbRange */ } return 0; }
static int FieldInfo_get_range(lua_State* L) { /* The TvbRange covering this field */ FieldInfo fi = checkFieldInfo(L,1); if (push_TvbRange (L, fi->ds_tvb, fi->start, fi->length)) { return 1; } return 0; }
/* WSLUA_ATTRIBUTE FieldInfo_range RO The `TvbRange` covering the bytes of this field in a Tvb. */ static int FieldInfo_get_range(lua_State* L) { FieldInfo fi = checkFieldInfo(L,1); if (push_TvbRange (L, fi->ws_fi->ds_tvb, fi->ws_fi->start, fi->ws_fi->length)) { return 1; } return 0; }
WSLUA_METHOD Tvb_range(lua_State* L) { /* Creates a tvbr from this Tvb. This is used also as the Tvb:__call() metamethod. */ #define WSLUA_OPTARG_Tvb_range_OFFSET 2 /* The offset (in octets) from the beginning of the Tvb. Defaults to 0. */ #define WSLUA_OPTARG_Tvb_range_LENGTH 3 /* The length (in octets) of the range. Defaults to until the end of the Tvb. */ Tvb tvb = checkTvb(L,1); int offset = luaL_optint(L,WSLUA_OPTARG_Tvb_range_OFFSET,0); int len = luaL_optint(L,WSLUA_OPTARG_Tvb_range_LENGTH,-1); if (push_TvbRange(L,tvb->ws_tvb,offset,len)) { WSLUA_RETURN(1); /* The TvbRange */ } return 0; }
WSLUA_METHOD Tvb_range(lua_State* L) { /* Creates a `TvbRange` from this `Tvb`. */ #define WSLUA_OPTARG_Tvb_range_OFFSET 2 /* The offset (in octets) from the beginning of the `Tvb`. Defaults to 0. */ #define WSLUA_OPTARG_Tvb_range_LENGTH 3 /* The length (in octets) of the range. Defaults to until the end of the `Tvb`. */ Tvb tvb = checkTvb(L,1); int offset = (int) luaL_optinteger(L,WSLUA_OPTARG_Tvb_range_OFFSET,0); int len = (int) luaL_optinteger(L,WSLUA_OPTARG_Tvb_range_LENGTH,-1); if (push_TvbRange(L,tvb->ws_tvb,offset,len)) { WSLUA_RETURN(1); /* The TvbRange */ } return 0; }