aboutsummaryrefslogtreecommitdiffstats
path: root/epan/filesystem.c
diff options
context:
space:
mode:
authorstandel <standel@f5534014-38df-0310-8fa8-9805f1628bb7>2009-05-29 21:10:40 +0000
committerstandel <standel@f5534014-38df-0310-8fa8-9805f1628bb7>2009-05-29 21:10:40 +0000
commitcf3c8539a7dae5a68e9308fdad75291607731174 (patch)
tree0ee2757e438e9d9db9dd0ddab19f0e84f3f29f03 /epan/filesystem.c
parent3bc9faf70086dab37bade7aa49d7abfae47afc4e (diff)
python binding for wireshark (first commit)
* ability to write dissectors with python for wireshark. documentation (http://wiki.wireshark.org/Python) git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@28529 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/filesystem.c')
-rw-r--r--epan/filesystem.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/epan/filesystem.c b/epan/filesystem.c
index 8b899eda0a..010bddc53a 100644
--- a/epan/filesystem.c
+++ b/epan/filesystem.c
@@ -669,6 +669,102 @@ get_datafile_dir(void)
return datafile_dir;
}
+#ifdef HAVE_PYTHON
+/*
+ * Find the directory where the python dissectors are stored.
+ *
+ * On Windows, we use the "py_dissector" subdirectory of the datafile directory.
+ *
+ * On UN*X, we use the PLUGIN_DIR value supplied by the configure
+ * script, unless we think we're being run from the build directory,
+ * in which case we use the "py_dissector" subdirectory of the datafile directory.
+ *
+ * In both cases, we then use the subdirectory of that directory whose
+ * name is the version number.
+ *
+ * XXX - if we think we're being run from the build directory, perhaps we
+ * should have the plugin code not look in the version subdirectory
+ * of the plugin directory, but look in all of the subdirectories
+ * of the plugin directory, so it can just fetch the plugins built
+ * as part of the build process.
+ */
+static const char *wspython_dir = NULL;
+
+static void
+init_wspython_dir(void)
+{
+#ifdef _WIN32
+ /*
+ * On Windows, the data file directory is the installation
+ * directory; the python dissectors are stored under it.
+ *
+ * Assume we're running the installed version of Wireshark;
+ * on Windows, the data file directory is the directory
+ * in which the Wireshark binary resides.
+ */
+ wspython_dir = g_strdup_printf("%s\\python\\%s", get_datafile_dir(),
+ VERSION);
+
+ /*
+ * Make sure that pathname refers to a directory.
+ */
+ if (test_for_directory(wspython_dir) != EISDIR) {
+ /*
+ * Either it doesn't refer to a directory or it
+ * refers to something that doesn't exist.
+ *
+ * Assume that means we're running a version of
+ * Wireshark we've built in a build directory,
+ * in which case {datafile dir}\python is the
+ * top-level plugins source directory, and use
+ * that directory and set the "we're running in
+ * a build directory" flag, so the plugin
+ * scanner will check all subdirectories of that
+ * directory for python dissectors.
+ */
+ g_free( (gpointer) wspython_dir);
+ wspython_dir = g_strdup_printf("%s\\python", get_datafile_dir());
+ running_in_build_directory_flag = TRUE;
+ }
+#else
+ if (running_in_build_directory_flag) {
+ /*
+ * We're (probably) being run from the build directory and
+ * weren't started with special privileges, so we'll use
+ * the "python" subdirectory of the datafile directory
+ * (the datafile directory is the build directory).
+ */
+ wspython_dir = g_strdup_printf("%s/epan/wspython/", get_datafile_dir());
+ } else {
+ if (getenv("WIRESHARK_PYTHON_DIR") && !started_with_special_privs()) {
+ /*
+ * The user specified a different directory for plugins
+ * and we aren't running with special privileges.
+ */
+ wspython_dir = g_strdup(getenv("WIRESHARK_PYTHON_DIR"));
+ } else {
+ wspython_dir = PYTHON_DIR;
+ }
+ }
+#endif
+}
+#endif /* HAVE_PYTHON */
+
+/*
+ * Get the directory in which the python dissectors are stored.
+ */
+const char *
+get_wspython_dir(void)
+{
+#ifdef HAVE_PYTHON
+ if (!wspython_dir) init_wspython_dir();
+ return wspython_dir;
+#else
+ return NULL;
+#endif
+}
+
+
#ifdef HAVE_PLUGINS
/*
* Find the directory where the plugins are stored.