28#include <ws_log_defs.h>
54#include <epan/wslua/declare_wslua.h>
60#define WSLUA_INIT_ROUTINES "init_routines"
61#define WSLUA_PREFS_CHANGED "prefs_changed"
87#define wslua_toint(L,i) (int) ( lua_tointeger(L,i) )
88#define wslua_toint32(L,i) (int32_t) ( lua_tointeger(L,i) )
89#define wslua_toint64(L,i) (int64_t) ( lua_tonumber(L,i) )
90#define wslua_touint64(L,i) (uint64_t) ( lua_tonumber(L,i) )
92#define wslua_checkint(L,i) (int) ( luaL_checkinteger(L,i) )
93#define wslua_checkint32(L,i) (int32_t) ( luaL_checkinteger(L,i) )
94#define wslua_checkint64(L,i) (int64_t) ( luaL_checknumber(L,i) )
95#define wslua_checkuint64(L,i) (uint64_t) ( luaL_checknumber(L,i) )
97#define wslua_optint(L,i,d) (int) ( luaL_optinteger(L,i,d) )
98#define wslua_optint32(L,i,d) (int32_t) ( luaL_optinteger(L,i,d) )
99#define wslua_optint64(L,i,d) (int64_t) ( luaL_optnumber(L,i,d) )
100#define wslua_optuint64(L,i,d) (uint64_t) ( luaL_optnumber(L,i,d) )
107#if LUA_VERSION_NUM < 503
108#define wslua_touint(L,i) (unsigned) ( lua_tounsigned(L,i) )
109#define wslua_touint32(L,i) (uint32_t) ( lua_tounsigned(L,i) )
110#define wslua_checkuint(L,i) (unsigned) ( luaL_checkunsigned(L,i) )
111#define wslua_checkuint32(L,i) (uint32_t) ( luaL_checkunsigned(L,i) )
112#define wslua_optuint(L,i,d) (unsigned) ( luaL_optunsigned(L,i,d) )
113#define wslua_optuint32(L,i,d) (uint32_t) ( luaL_optunsigned(L,i,d) )
115#define wslua_touint(L,i) (unsigned) ( lua_tointeger(L,i) )
116#define wslua_touint32(L,i) (uint32_t) ( lua_tointeger(L,i) )
117#define wslua_checkuint(L,i) (unsigned) ( luaL_checkinteger(L,i) )
118#define wslua_checkuint32(L,i) (uint32_t) ( luaL_checkinteger(L,i) )
119#define wslua_optuint(L,i,d) (unsigned) ( luaL_optinteger(L,i,d) )
120#define wslua_optuint32(L,i,d) (uint32_t) ( luaL_optinteger(L,i,d) )
219 int expert_info_table_ref;
226 bool is_postdissector;
281typedef void (*tap_extractor_t)(lua_State*,
const void*);
286 tap_extractor_t extractor;
327 char* internal_description;
335 int seq_read_close_ref;
336 int can_write_encap_ref;
357typedef struct {
const char* name; tap_extractor_t extractor; }
tappable_t;
369typedef GByteArray* ByteArray;
378typedef int64_t Int64;
379typedef uint64_t UInt64;
396typedef tvbparse_action_t* Shortcut;
411#define WSLUA_CLASS_DEFINE(C,check_code) \
412 WSLUA_CLASS_DEFINE_BASE(C,check_code,NULL)
414#define WSLUA_CLASS_DEFINE_BASE(C,check_code,retval) \
415C to##C(lua_State* L, int idx) { \
416 C* v = (C*)lua_touserdata (L, idx); \
417 if (!v) luaL_error(L, "bad argument %d (%s expected, got %s)", idx, #C, lua_typename(L, lua_type(L, idx))); \
418 return v ? *v : retval; \
420C check##C(lua_State* L, int idx) { \
422 luaL_checktype(L,idx,LUA_TUSERDATA); \
423 p = (C*)luaL_checkudata(L, idx, #C); \
425 return p ? *p : retval; \
427C* push##C(lua_State* L, C v) { \
429 luaL_checkstack(L,2,"Unable to grow stack\n"); \
430 p = (C*)lua_newuserdata(L,sizeof(C)); *p = v; \
431 luaL_getmetatable(L, #C); lua_setmetatable(L, -2); \
434bool is##C(lua_State* L,int i) { \
436 if(!lua_isuserdata(L,i)) return false; \
437 p = lua_touserdata(L, i); \
438 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
439 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
441 return p ? true : false; \
443C shift##C(lua_State* L,int i) { \
445 if(!lua_isuserdata(L,i)) return retval; \
446 p = (C*)lua_touserdata(L, i); \
447 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
448 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
450 if (p) { lua_remove(L,i); return *p; }\
456 const char *fieldname;
457 lua_CFunction getfunc;
458 lua_CFunction setfunc;
462#define WSLUA_TYPEOF_FIELD "__typeof"
467#define WSLUA_REGISTER_GC(C) \
468 luaL_getmetatable(L, #C); \
471 lua_pushcfunction(L, C ## __gc); \
472 lua_setfield(L, -2, "__gc"); \
476#define __WSLUA_REGISTER_META(C, ATTRS) { \
477 const wslua_class C ## _class = { \
479 .instance_meta = C ## _meta, \
482 wslua_register_classinstance_meta(L, &C ## _class); \
483 WSLUA_REGISTER_GC(C); \
486#define WSLUA_REGISTER_META(C) __WSLUA_REGISTER_META(C, NULL)
487#define WSLUA_REGISTER_META_WITH_ATTRS(C) \
488 __WSLUA_REGISTER_META(C, C ## _attributes)
490#define __WSLUA_REGISTER_CLASS(C, ATTRS) { \
491 const wslua_class C ## _class = { \
493 .class_methods = C ## _methods, \
494 .class_meta = C ## _meta, \
495 .instance_methods = C ## _methods, \
496 .instance_meta = C ## _meta, \
499 wslua_register_class(L, &C ## _class); \
500 WSLUA_REGISTER_GC(C); \
503#define WSLUA_REGISTER_CLASS(C) __WSLUA_REGISTER_CLASS(C, NULL)
504#define WSLUA_REGISTER_CLASS_WITH_ATTRS(C) \
505 __WSLUA_REGISTER_CLASS(C, C ## _attributes)
507#define WSLUA_INIT(L) \
509 wslua_register_classes(L); \
510 wslua_register_functions(L);
514#define WSLUA_FUNCTION extern int
516#define WSLUA_INTERNAL_FUNCTION extern int
518#define WSLUA_REGISTER_FUNCTION(name) { lua_pushcfunction(L, wslua_## name); lua_setglobal(L, #name); }
520#define WSLUA_REGISTER extern int
522#define WSLUA_METHOD static int
523#define WSLUA_CONSTRUCTOR static int
524#define WSLUA_ATTR_SET static int
525#define WSLUA_ATTR_GET static int
526#define WSLUA_METAMETHOD static int
528#define WSLUA_METHODS static const luaL_Reg
529#define WSLUA_META static const luaL_Reg
530#define WSLUA_CLASS_FNREG(class,name) { #name, class##_##name }
531#define WSLUA_CLASS_FNREG_ALIAS(class,aliasname,name) { #aliasname, class##_##name }
532#define WSLUA_CLASS_MTREG(class,name) { "__" #name, class##__##name }
534#define WSLUA_ATTRIBUTES static const wslua_attribute_table
536#define WSLUA_ATTRIBUTE_RWREG(class,name) { #name, class##_get_##name, class##_set_##name }
537#define WSLUA_ATTRIBUTE_ROREG(class,name) { #name, class##_get_##name, NULL }
538#define WSLUA_ATTRIBUTE_WOREG(class,name) { #name, NULL, class##_set_##name }
540#define WSLUA_ATTRIBUTE_FUNC_SETTER(C,field) \
541 static int C##_set_##field (lua_State* L) { \
542 C obj = check##C (L,1); \
543 if (! lua_isfunction(L,-1) ) \
544 return luaL_error(L, "%s's attribute `%s' must be a function", #C , #field ); \
545 if (obj->field##_ref != LUA_NOREF) \
547 luaL_unref(L, LUA_REGISTRYINDEX, obj->field##_ref); \
548 obj->field##_ref = luaL_ref(L, LUA_REGISTRYINDEX); \
552 typedef void __dummy##C##_set_##field
554#define WSLUA_ATTRIBUTE_GET(C,name,block) \
555 static int C##_get_##name (lua_State* L) { \
556 C obj = check##C (L,1); \
561 typedef void __dummy##C##_get_##name
563#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(C,name,member) \
564 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushboolean(L, obj->member );})
566#define WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,name,member) \
567 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushinteger(L,(lua_Integer)(obj->member));})
569#define WSLUA_ATTRIBUTE_INTEGER_GETTER(C,member) \
570 WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,member,member)
572#define WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(C,name,block) \
573 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(block));})
575#define WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,name,member) \
576 WSLUA_ATTRIBUTE_GET(C,name, { \
577 lua_pushstring(L,obj->member); \
580#define WSLUA_ATTRIBUTE_STRING_GETTER(C,member) \
581 WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,member,member)
583#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(C,name,member,option) \
584 WSLUA_ATTRIBUTE_GET(C,name, { \
586 if ((obj->member) && (obj->member->len > 0)) { \
587 if (wtap_block_get_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, &str) == WTAP_OPTTYPE_SUCCESS) { \
588 lua_pushstring(L,str); \
597#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(C,name,member,option) \
598 WSLUA_ATTRIBUTE_GET(C,name, { \
600 if ((obj->member) && (obj->member->len > 0)) { \
601 if (wtap_block_get_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, &str) == WTAP_OPTTYPE_SUCCESS) { \
602 lua_pushstring(L,str); \
607#define WSLUA_ATTRIBUTE_SET(C,name,block) \
608 static int C##_set_##name (lua_State* L) { \
609 C obj = check##C (L,1); \
614 typedef void __dummy##C##_set_##name
616#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER(C,name,member) \
617 WSLUA_ATTRIBUTE_SET(C,name, { \
618 if (! lua_isboolean(L,-1) ) \
619 return luaL_error(L, "%s's attribute `%s' must be a boolean", #C , #name ); \
620 obj->member = lua_toboolean(L,-1); \
625#define WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,name,member,cast) \
626 WSLUA_ATTRIBUTE_SET(C,name, { \
627 if (! lua_isinteger(L,-1) ) \
628 return luaL_error(L, "%s's attribute `%s' must be an integer", #C , #name ); \
629 obj->member = (cast) wslua_toint32(L,-1); \
632#define WSLUA_ATTRIBUTE_INTEGER_SETTER(C,member,cast) \
633 WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,member,member,cast)
635#define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,member,need_free) \
636 static int C##_set_##field (lua_State* L) { \
637 C obj = check##C (L,1); \
639 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
640 s = g_strdup(lua_tostring(L,-1)); \
642 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
644 if (obj->member != NULL && need_free) \
645 g_free((void*) obj->member); \
650 typedef void __dummy##C##_set_##field
652#define WSLUA_ATTRIBUTE_STRING_SETTER(C,field,need_free) \
653 WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,field,need_free)
655#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(C,field,member,option) \
656 static int C##_set_##field (lua_State* L) { \
657 C obj = check##C (L,1); \
659 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
660 s = g_strdup(lua_tostring(L,-1)); \
662 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
664 if ((obj->member) && (obj->member->len > 0)) { \
665 wtap_block_set_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, s, strlen(s)); \
671 typedef void __dummy##C##_set_##field
673#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(C,field,member,option) \
674 static int C##_set_##field (lua_State* L) { \
675 C obj = check##C (L,1); \
677 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
678 s = g_strdup(lua_tostring(L,-1)); \
680 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
682 if ((obj->member) && (obj->member->len > 0)) { \
683 wtap_block_set_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, s, strlen(s)); \
689 typedef void __dummy##C##_set_##field
691#define WSLUA_ERROR(name,error) { luaL_error(L, "%s%s", #name ": ", error); }
692#define WSLUA_ARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); }
693#define WSLUA_OPTARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); }
695#define WSLUA_REG_GLOBAL_BOOL(L,n,v) { lua_pushboolean(L,v); lua_setglobal(L,n); }
696#define WSLUA_REG_GLOBAL_STRING(L,n,v) { lua_pushstring(L,v); lua_setglobal(L,n); }
697#define WSLUA_REG_GLOBAL_INTEGER(L,n,v) { lua_pushinteger(L,v); lua_setglobal(L,n); }
699#define WSLUA_RETURN(i) return (i)
701#define WSLUA_API extern
706#define FAIL_ON_NULL(s) if (! *p) luaL_argerror(L,idx,"null " s)
708#define FAIL_ON_NULL_OR_EXPIRED(s) if (!*p) { \
709 luaL_argerror(L,idx,"null " s); \
710 } else if ((*p)->expired) { \
711 luaL_argerror(L,idx,"expired " s); \
715#define CLEAR_OUTSTANDING(C, marker, marker_val) void clear_outstanding_##C(void) { \
716 while (outstanding_##C->len) { \
717 C p = (C)g_ptr_array_remove_index_fast(outstanding_##C,0); \
719 if (p->marker != marker_val) \
720 p->marker = marker_val; \
727#define WSLUA_CLASS_DECLARE(C) \
728extern C to##C(lua_State* L, int idx); \
729extern C check##C(lua_State* L, int idx); \
730extern C* push##C(lua_State* L, C v); \
731extern int C##_register(lua_State* L); \
732extern bool is##C(lua_State* L,int i); \
733extern C shift##C(lua_State* L,int i)
737#define THROW_LUA_ERROR(...) \
738 THROW_FORMATTED(DissectorError, __VA_ARGS__)
759#define WRAP_NON_LUA_EXCEPTIONS(code) \
761 volatile bool has_error = false; \
764 } CATCH3(BoundsError, FragmentBoundsError, ScsiBoundsError) { \
765 show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
767 show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
768 lua_pushfstring(L, "%s: %s", __func__, GET_MESSAGE ? GET_MESSAGE : "Malformed packet"); \
771 if (has_error) { lua_error(L); } \
778extern bool lua_initialized;
779extern int lua_dissectors_table_ref;
780extern int lua_heur_dissectors_table_ref;
782WSLUA_DECLARE_CLASSES()
783WSLUA_DECLARE_FUNCTIONS()
785extern lua_State* wslua_state(
void);
806extern int wslua__concat(lua_State* L);
807extern bool wslua_toboolean(lua_State* L,
int n);
808extern bool wslua_checkboolean(lua_State* L,
int n);
809extern bool wslua_optbool(lua_State* L,
int n,
bool def);
810extern lua_Integer wslua_tointeger(lua_State* L,
int n);
811extern int wslua_optboolint(lua_State* L,
int n,
int def);
812extern const char* wslua_checklstring_only(lua_State* L,
int n,
size_t *l);
813extern const char* wslua_checkstring_only(lua_State* L,
int n);
814extern void wslua_setfuncs(lua_State *L,
const luaL_Reg *l,
int nup);
815extern const char* wslua_typeof_unknown;
816extern const char* wslua_typeof(lua_State *L,
int idx);
817extern bool wslua_get_table(lua_State *L,
int idx,
const char *name);
818extern bool wslua_get_field(lua_State *L,
int idx,
const char *name);
821extern expert_field* wslua_get_expert_field(
const int group,
const int severity);
822extern void wslua_prefs_changed(
void);
823extern void proto_register_lua(
void);
824extern GString* lua_register_all_taps(
void);
826extern bool wslua_has_field_extractors(
void);
827extern void lua_prime_all_fields(
proto_tree* tree);
829extern int Proto_commit(lua_State* L);
833extern void clear_outstanding_FuncSavers(
void);
835extern void Int64_pack(lua_State* L, luaL_Buffer *b,
int idx,
bool asLittleEndian);
836extern int Int64_unpack(lua_State* L,
const char *buff,
bool asLittleEndian);
837extern void UInt64_pack(lua_State* L, luaL_Buffer *b,
int idx,
bool asLittleEndian);
838extern int UInt64_unpack(lua_State* L,
const char *buff,
bool asLittleEndian);
839extern uint64_t getUInt64(lua_State *L,
int i);
842extern int push_wsluaTvb(lua_State* L,
Tvb t);
843extern bool push_TvbRange(lua_State* L,
tvbuff_t* tvb,
int offset,
int len);
844extern void clear_outstanding_Tvb(
void);
845extern void clear_outstanding_TvbRange(
void);
848extern void clear_outstanding_Pinfo(
void);
849extern void clear_outstanding_Column(
void);
850extern void clear_outstanding_Columns(
void);
851extern void clear_outstanding_PrivateTable(
void);
853extern int get_hf_wslua_text(
void);
855extern void clear_outstanding_TreeItem(
void);
858extern void clear_outstanding_FieldInfo(
void);
860extern void wslua_print_stack(
char* s, lua_State* L);
862extern void wslua_init(register_cb cb,
void *client_data);
863extern void wslua_early_cleanup(
void);
864extern void wslua_cleanup(
void);
866extern tap_extractor_t wslua_get_tap_extractor(
const char* name);
867extern int wslua_set_tap_enums(lua_State* L);
871extern char* wslua_get_actual_filename(
const char* fname);
873extern int wslua_bin2hex(lua_State* L,
const uint8_t* data,
const unsigned len,
const bool lowercase,
const char* sep);
874extern int wslua_hex2bin(lua_State* L,
const char* data,
const unsigned len,
const char* sep);
875extern int luaopen_rex_pcre2(lua_State *L);
877extern const char* get_current_plugin_version(
void);
878extern void clear_current_plugin_version(
void);
880extern int wslua_deregister_heur_dissectors(lua_State* L);
881extern int wslua_deregister_protocols(lua_State* L);
882extern int wslua_deregister_dissector_tables(lua_State* L);
883extern int wslua_deregister_listeners(lua_State* L);
884extern int wslua_deregister_fields(lua_State* L);
885extern int wslua_deregister_filehandlers(lua_State* L);
886extern void wslua_deregister_menus(
void);
888extern void wslua_init_wtap_filetypes(lua_State* L);
#define PREF_UINT
Definition prefs-int.h:90
Definition tap-funnel.c:27
Definition packet_info.h:43
Definition tvbparse.h:142
Definition tvbparse.h:130
Type for defining new classes.
Definition wslua.h:795
const wslua_attribute_table * attrs
Definition wslua.h:801
const luaL_Reg * class_meta
Definition wslua.h:798
const char * name
Definition wslua.h:796
const luaL_Reg * class_methods
Definition wslua.h:797
const luaL_Reg * instance_methods
Definition wslua.h:799
const luaL_Reg * instance_meta
Definition wslua.h:800
struct _wslua_pref_t::@495::@496 enum_info
bool radio_buttons
Definition wslua.h:198
char * default_s
Definition wslua.h:203
uint32_t max_value
Definition wslua.h:195
const enum_val_t * enumvals
Definition wslua.h:197
union _wslua_pref_t::@495 info
Definition conversation.h:227
Definition column-info.h:62
Definition epan_dissect.h:28
Definition prefs-int.h:27
Definition progress_frame.h:31
Definition tvbuff-int.h:35
Definition file_wrappers.c:215
void wslua_register_class(lua_State *L, const wslua_class *cls_def)
Definition wslua_internals.c:547
ProtoField wslua_is_field_available(lua_State *L, const char *field_abbr)
Definition wslua_proto.c:714
void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def)
Definition wslua_internals.c:470
struct _wslua_class wslua_class
Type for defining new classes.
pref_type_t
Definition wslua.h:171