Wireshark will try to load a file named <command>init.lua</command> in the user's
directory.
</para>
+ <para>
+ Wireshark will also load all files with <command>.lua</command> suffix from both the
+ global and the personal plugins directory.
+ </para>
<para>
The command line option <command>-X lua_script:<file.lua></command> can be used to
load lua scripts as well.
#include <wiretap/wtap.h> /* for WTAP_ERR_SHORT_WRITE */
#define PROFILES_DIR "profiles"
+#define PLUGINS_DIR_NAME "plugins"
+
#define U3_MY_CAPTURES "\\My Captures"
char *persconffile_dir = NULL;
}
-#ifdef HAVE_PLUGINS
+#if defined(HAVE_PLUGINS) || defined(HAVE_LUA_5_1)
/*
* Find the directory where the plugins are stored.
*
}
#endif
}
-#endif /* HAVE_PLUGINS */
+#endif /* HAVE_PLUGINS || HAVE_LUA_5_1 */
/*
* Get the directory in which the plugins are stored.
const char *
get_plugin_dir(void)
{
-#ifdef HAVE_PLUGINS
+#if defined(HAVE_PLUGINS) || defined(HAVE_LUA_5_1)
if (!plugin_dir) init_plugin_dir();
return plugin_dir;
#else
filename);
}
+/* Get the personal plugin dir */
+/* Return value is malloced so the caller should g_free() it. */
+char *
+get_plugins_pers_dir(void)
+{
+ return get_persconffile_path(PLUGINS_DIR_NAME, FALSE, FALSE);
+}
+
/* Delete a file */
gboolean
deletefile(const char *path)
*/
extern char *get_datafile_path(const char *filename);
+/*
+ * Get the personal plugin dir.
+ */
+extern char *get_plugins_pers_dir(void);
+
/*
* Get the directory in which files that, at least on UNIX, are
* system files (such as "/etc/ethers") are stored; on Windows,
vals_status DATA
value_is_in_range
write_prefs
+wslua_plugin_list DATA
wtap_nstime_to_sec
xml_escape
xml_get_attrib
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
- * Copyright 1999 Gerald Combs
+ * Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
#include "report_err.h"
/* linked list of all plugins */
-plugin *plugin_list;
-
-#define PLUGINS_DIR_NAME "plugins"
+plugin *plugin_list = NULL;
/*
* add a new plugin to the list
}
}
-/* get the personal plugin dir */
-/* Return value is malloced so the caller should g_free() it. */
-char *get_plugins_pers_dir(void)
-{
- return get_persconffile_path(PLUGINS_DIR_NAME, FALSE, FALSE);
-}
/*
* init plugins
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
- * Copyright 1999 Gerald Combs
+ * Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
extern void register_all_wiretap_modules(void);
extern void register_all_codecs(void);
-/* get the personal plugin dir */
-/* Return value is g_malloced so the caller should g_free() it. */
-extern char *get_plugins_pers_dir(void);
-
#endif /* __PLUGINS_H__ */
#include <epan/ex-opt.h>
#include <wsutil/privileges.h>
#include <wsutil/file_util.h>
+#include "init_wslua.h"
static lua_State* L = NULL;
tvbuff_t* lua_tvb;
int lua_malformed;
int lua_dissectors_table_ref;
+wslua_plugin *wslua_plugin_list = NULL;
dissector_handle_t lua_data_handle;
return 0;
}
-static void lua_load_script(const gchar* filename) {
+static void wslua_add_plugin(gchar *name, gchar *version)
+{
+ wslua_plugin *new_plug, *lua_plug;
+
+ lua_plug = wslua_plugin_list;
+ new_plug = (wslua_plugin *)g_malloc(sizeof(wslua_plugin));
+
+ if (!lua_plug) { /* the list is empty */
+ wslua_plugin_list = new_plug;
+ } else {
+ while (lua_plug->next != NULL) {
+ lua_plug = lua_plug->next;
+ }
+ lua_plug->next = new_plug;
+ }
+
+ new_plug->name = name;
+ new_plug->version = version;
+ new_plug->next = NULL;
+}
+
+static gboolean lua_load_script(const gchar* filename) {
FILE* file;
+ int error;
if (! ( file = ws_fopen(filename,"r")) ) {
report_open_failure(filename,errno,FALSE);
- return;
+ return FALSE;
}
lua_settop(L,0);
lua_pushcfunction(L,lua_main_error_handler);
- switch (lua_load(L,getF,file,filename)) {
+ error = lua_load(L,getF,file,filename);
+ switch (error) {
case 0:
lua_pcall(L,0,0,1);
fclose(file);
- return;
+ return TRUE;
case LUA_ERRSYNTAX: {
report_failure("Lua: syntax error during precompilation of `%s':\n%s",filename,lua_tostring(L,-1));
fclose(file);
- return;
+ return FALSE;
}
case LUA_ERRMEM:
report_failure("Lua: memory allocation error during execution of %s",filename);
fclose(file);
- return;
+ return FALSE;
}
+ report_failure("Lua: unknown error during execution of %s: %d",filename,error);
+ fclose(file);
+ return FALSE;
}
static void basic_logger(const gchar *log_domain _U_,
return 0;
}
+static void lua_load_plugins (gboolean global)
+{
+ WS_DIR *dir; /* scanned directory */
+ WS_DIRENT *file; /* current file */
+ gchar *persdir, *filename, *dot;
+ const gchar *dirname, *name;
+
+ if (global) {
+ persdir = NULL;
+ dirname = get_plugin_dir();
+ } else {
+ persdir = get_plugins_pers_dir();
+ dirname = persdir;
+ }
+
+ if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL) {
+ while ((file = ws_dir_read_name(dir)) != NULL) {
+ name = ws_dir_get_name(file);
+
+ if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
+ continue; /* skip "." and ".." */
+
+ /* skip anything but files with .lua suffix */
+ dot = strrchr(name, '.');
+ if (dot == NULL || strcmp(dot+1, "lua") != 0)
+ continue;
+
+ filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", dirname, name);
+ if (file_exists(filename)) {
+ if (lua_load_script(filename)) {
+ wslua_add_plugin(g_strdup(name), g_strdup(""));
+ }
+ }
+ g_free (filename);
+ }
+ }
+
+ if (persdir)
+ g_free(persdir);
+}
+
int wslua_init(lua_State* LS) {
gchar* filename;
const funnel_ops_t* ops = funnel_get_funnel_ops();
return 0;
}
+ /* load global scripts */
+ lua_load_plugins(TRUE);
+
/* check whether we should run other scripts even if running superuser */
lua_pushstring(L,"run_user_scripts_when_superuser");
lua_gettable(L, LUA_GLOBALSINDEX);
if (( file_exists(filename))) {
lua_load_script(filename);
- g_free(filename);
- filename = NULL;
}
+ g_free(filename);
+ filename = NULL;
+
+ /* load user scripts */
+ lua_load_plugins(FALSE);
+
+ /* load scripts from command line */
while((filename = (gchar *)ex_opt_get_next("lua_script"))) {
lua_load_script(filename);
}
--- /dev/null
+/* init_wslua.h
+ * definitions for wslua plugins structures
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __INIT_WSLUA_H__
+#define __INIT_WSLUA_H__
+
+#include <glib.h>
+
+typedef struct _wslua_plugin {
+ gchar *name; /* plugin name */
+ gchar *version; /* plugin version */
+ struct _wslua_plugin *next;
+} wslua_plugin;
+
+WS_VAR_IMPORT wslua_plugin *wslua_plugin_list;
+
+#endif /* __INIT_WSLUA_H__ */
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
- * Copyright 2000 Gerald Combs
+ * Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
about_folders_row(table, "Program", constpath,
"program files");
-#ifdef HAVE_PLUGINS
+#if defined(HAVE_PLUGINS) || defined(HAVE_LUA_5_1)
/* pers plugins */
path = get_plugins_pers_dir();
about_folders_row(table, "Personal Plugins", path,
GtkWidget *main_vb, *main_nb, *bbox, *ok_btn;
GtkWidget *page_lb, *about_page, *folders_page;
-#ifdef HAVE_PLUGINS
+#if defined(HAVE_PLUGINS) || defined(HAVE_LUA_5_1)
GtkWidget *plugins_page;
#endif
page_lb = gtk_label_new("Folders");
gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), folders_page, page_lb);
-#ifdef HAVE_PLUGINS
+#if defined(HAVE_PLUGINS) || defined(HAVE_LUA_5_1)
plugins_page = about_plugins_page_new();
page_lb = gtk_label_new("Plugins");
gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), plugins_page, page_lb);
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
- * Copyright 1999 Gerald Combs
+ * Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
#include <gtk/gtk.h>
-#include <epan/plugins.h>
+#include "epan/plugins.h"
+#ifdef HAVE_LUA_5_1
+#include "epan/wslua/init_wslua.h"
+#endif
#include "../globals.h"
#include "gtk/plugins_dlg.h"
-#ifdef HAVE_PLUGINS
+#if defined(HAVE_PLUGINS) || defined(HAVE_LUA_5_1)
/*
* Fill the list widget with a list of the plugin modules.
static void
plugins_scan(GtkWidget *list)
{
+#ifdef HAVE_PLUGINS
plugin *pt_plug;
+ const char *sep;
+#endif
+#ifdef HAVE_LUA_5_1
+ wslua_plugin *lua_plug;
+#endif
GString *type;
- const char *sep;
+#ifdef HAVE_PLUGINS
for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
{
type = g_string_new("");
2, type->str, -1);
g_string_free(type, TRUE);
}
+#endif
+
+#ifdef HAVE_LUA_5_1
+ for (lua_plug = wslua_plugin_list; lua_plug != NULL; lua_plug = lua_plug->next)
+ {
+ type = g_string_new("");
+ type = g_string_append(type, "lua script");
+
+ simple_list_append(list, 0, lua_plug->name, 1, lua_plug->version, 2, type->str, -1);
+ g_string_free(type, TRUE);
+ }
+#endif
}
return scrolledwindow;
}
-#endif /* HAVE_PLUGINS */
+#endif /* HAVE_PLUGINS || HAVE_LUA_5_1 */