aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2013-09-07 11:27:38 +0000
committerStig Bjørlykke <stig@bjorlykke.org>2013-09-07 11:27:38 +0000
commit7d3d67407cd4b57cac6f6253a41ced5215c97207 (patch)
treefaf6608b328397db69e2780c8022ad6d8feec646 /epan/wslua
parenta8638eec90bace9997e084bf4ab15f0485ac1106 (diff)
Added support for a "prefs_change" function in Lua scripts, which is called
when the preferences for the dissector are changed. This is not a 100% correct implementation at the time because the prefs_changed function in all Lua plugins will be called whenever a preference in a single Lua plugin is changed. svn path=/trunk/; revision=51818
Diffstat (limited to 'epan/wslua')
-rw-r--r--epan/wslua/init_wslua.c15
-rw-r--r--epan/wslua/wslua.h3
-rw-r--r--epan/wslua/wslua_proto.c34
3 files changed, 44 insertions, 8 deletions
diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c
index 5e16c53bde..5c43c158ff 100644
--- a/epan/wslua/init_wslua.c
+++ b/epan/wslua/init_wslua.c
@@ -184,6 +184,17 @@ static void wslua_init_routine(void) {
}
+static int prefs_changed_error_handler(lua_State* LS) {
+ const gchar* error = lua_tostring(LS,1);
+ report_failure("Lua: Error During execution of prefs apply callback:\n %s",error);
+ return 0;
+}
+
+void wslua_prefs_changed(void) {
+ if (L) {
+ iter_table_and_call(L, WSLUA_PREFS_CHANGED,prefs_changed_error_handler);
+ }
+}
static const char *getF(lua_State *LS _U_, void *ud, size_t *size)
{
@@ -381,6 +392,10 @@ int wslua_init(register_cb cb, gpointer client_data) {
lua_newtable (L);
lua_dissectors_table_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+ /* the preferences apply_cb table (accessible by the user) */
+ lua_newtable (L);
+ lua_setglobal(L, WSLUA_PREFS_CHANGED);
+
/* set running_superuser variable to its proper value */
WSLUA_REG_GLOBAL_BOOL(L,"running_superuser",started_with_special_privs());
diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h
index 0c1870e16f..3e99904b32 100644
--- a/epan/wslua/wslua.h
+++ b/epan/wslua/wslua.h
@@ -63,6 +63,7 @@
*/
#define WSLUA_INIT_ROUTINES "init_routines"
+#define WSLUA_PREFS_CHANGED "prefs_changed"
#define LOG_DOMAIN_LUA "wslua"
struct _wslua_tvb {
@@ -433,7 +434,7 @@ extern gboolean wslua_optbool(lua_State* L, int n, gboolean def);
extern const gchar* lua_shiftstring(lua_State* L,int idx);
extern void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
extern int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data);
-
+extern void wslua_prefs_changed(void);
extern void proto_register_lua(void);
extern GString* lua_register_all_taps(void);
extern void wslua_prime_dfilter(epan_dissect_t *edt);
diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c
index 61abf9fbb8..b69378ada1 100644
--- a/epan/wslua/wslua_proto.c
+++ b/epan/wslua/wslua_proto.c
@@ -318,7 +318,7 @@ WSLUA_METAMETHOD Prefs__newindex(lua_State* L) {
pref->label = g_strdup(name);
if (!prefs_p->proto->prefs_module) {
- prefs_p->proto->prefs_module = prefs_register_protocol(prefs_p->proto->hfid, NULL);
+ prefs_p->proto->prefs_module = prefs_register_protocol(prefs_p->proto->hfid, wslua_prefs_changed);
}
switch(pref->type) {
@@ -1395,6 +1395,23 @@ static int Proto_get_prefs(lua_State* L) {
return 1;
}
+static int Proto_set_prefs_changed(lua_State* L) {
+ Proto proto = toProto(L,1);
+
+ if (lua_isfunction(L,3)) {
+ /* insert the prefs changed callback into the prefs_changed table */
+ lua_getglobal(L, WSLUA_PREFS_CHANGED);
+ lua_replace(L, 1);
+ lua_pushstring(L,proto->name);
+ lua_replace(L, 2);
+ lua_settable(L,1);
+
+ } else {
+ luaL_argerror(L,3,"The prefs of a protocol must be a function");
+ }
+ return 0;
+}
+
static int Proto_set_init(lua_State* L) {
Proto proto = toProto(L,1);
@@ -1479,23 +1496,26 @@ typedef struct {
static const proto_actions_t proto_actions[] = {
/* WSLUA_ATTRIBUTE Proto_dissector RW The protocol's dissector, a function you define.
The called dissector function will be given three arguments of (1) a Tvb object, (2) a Pinfo object, and (3) a TreeItem object. */
- {"dissector",Proto_get_dissector, Proto_set_dissector},
+ {"dissector", Proto_get_dissector, Proto_set_dissector},
/* WSLUA_ATTRIBUTE Proto_fields RO The Fields Table of this dissector */
- {"fields" ,Proto_get_fields, Proto_set_fields},
+ {"fields", Proto_get_fields, Proto_set_fields},
/* WSLUA_ATTRIBUTE Proto_prefs RO The preferences of this dissector */
- {"prefs",Proto_get_prefs,NULL},
+ {"prefs", Proto_get_prefs, NULL},
+
+ /* WSLUA_ATTRIBUTE Proto_prefs WO The preferences changed routine of this dissector, a function you define. */
+ {"prefs_changed", NULL, Proto_set_prefs_changed},
/* WSLUA_ATTRIBUTE Proto_init WO The init routine of this dissector, a function you define.
The called init function is passed no arguments. */
- {"init",NULL,Proto_set_init},
+ {"init", NULL, Proto_set_init},
/* WSLUA_ATTRIBUTE Proto_name RO The name given to this dissector */
- {"name",Proto_get_name,NULL},
+ {"name", Proto_get_name, NULL},
/* WSLUA_ATTRIBUTE Proto_description RO The description given to this dissector */
- {"description",Proto_get_description,NULL},
+ {"description", Proto_get_description, NULL},
{NULL,NULL,NULL}
};