Make the "Preferences" dialog box use the new utilities to make the Esc
[obnox/wireshark/wip.git] / plugins.c
index 6d23fada2fe6ade2d323c434764e89f2f1a16b40..d809a384a077d31e1c6bda30eb68f573ed825c2d 100644 (file)
--- a/plugins.c
+++ b/plugins.c
@@ -1,7 +1,7 @@
 /* plugins.c
  * plugin routines
  *
- * $Id: plugins.c,v 1.6 2000/01/29 16:41:14 gram Exp $
+ * $Id: plugins.c,v 1.15 2000/05/05 09:32:10 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 #include "globals.h"
 #include "util.h"
 
+#ifdef PLUGINS_NEED_ADDRESS_TABLE
+#include "plugins/plugin_table.h"
+plugin_address_table_t patable;
+#endif
 
 /* linked list of all plugins */
 plugin *plugin_list;
+guint32 enabled_plugins_number;
 
-static gchar std_plug_dir[] = "/usr/lib/ethereal/plugins/0.8";
-static gchar local_plug_dir[] = "/usr/local/lib/ethereal/plugins/0.8";
+#ifdef WIN32
+static gchar std_plug_dir[] = "c:/program files/ethereal/plugins/0.8.7";
+static gchar local_plug_dir[] = "c:/ethereal/plugins/0.8.7";
+#else
+static gchar std_plug_dir[] = "/usr/lib/ethereal/plugins/0.8.7";
+static gchar local_plug_dir[] = "/usr/local/lib/ethereal/plugins/0.8.7";
+#endif
 static gchar *user_plug_dir = NULL;
 static gchar *plugin_status_file = NULL;
 
@@ -139,6 +149,7 @@ enable_plugin(const gchar *name, const gchar *version)
        if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
        {
            pt_plug->enabled = TRUE;
+           enabled_plugins_number++;
            return pt_plug;
        }
        pt_plug = pt_plug->next;
@@ -162,6 +173,7 @@ disable_plugin(const gchar *name, const gchar *version)
        if (!strcmp(pt_plug->name, name) && !strcmp(pt_plug->version, version))
        {
            pt_plug->enabled = FALSE;
+           enabled_plugins_number--;
            return pt_plug;
        }
        pt_plug = pt_plug->next;
@@ -289,7 +301,7 @@ check_plugin_status(gchar *name, gchar *version, GModule *handle,
     gchar   *ref_string;
     guint16  ref_string_len;
     gchar    line[512];
-    void   (*proto_init)();
+    void   (*plugin_init)(void*);
     dfilter *filter;
 
     if (!statusfile) return;
@@ -306,9 +318,18 @@ check_plugin_status(gchar *name, gchar *version, GModule *handle,
        else { /* found the plugin */
            if (line[ref_string_len+1] == '1') {
                enable_plugin(name, version);
-               if (g_module_symbol(handle, "proto_init", (gpointer*)&proto_init) == TRUE) {
-                   proto_init();
+               if (g_module_symbol(handle, "plugin_init", (gpointer*)&plugin_init) == TRUE) {
+#ifdef PLUGINS_NEED_ADDRESS_TABLE
+                   plugin_init(&patable);
+#else
+                   plugin_init(NULL);
+#endif
+               }
+#ifdef PLUGINS_NEED_ADDRESS_TABLE
+               else {
+                       return;
                }
+#endif
            }
 
            if (fgets(line, 512, statusfile) == NULL) return;
@@ -342,7 +363,7 @@ plugins_scan_dir(const char *dirname)
 #ifdef WIN32
 #define LT_LIB_EXT ".dll"
 #else
-#define LT_LIB_EXT ".la"
+#define LT_LIB_EXT ".so"
 #endif
 
     if (!plugin_status_file)
@@ -360,12 +381,11 @@ plugins_scan_dir(const char *dirname)
            if (!(strcmp(file->d_name, "..") &&
                  strcmp(file->d_name, "."))) continue;
 
-            /* skip anything but .la */
+            /* skip anything but files with LT_LIB_EXT */
             dot = strrchr(file->d_name, '.');
-            if (dot == NULL || ! strcmp(dot, LT_LIB_EXT)) continue;
+            if (dot == NULL || strcmp(dot, LT_LIB_EXT) != 0) continue;
 
            sprintf(filename, "%s/%s", dirname, file->d_name);
-
            if ((handle = g_module_open(filename, 0)) == NULL) continue;
            name = (gchar *)file->d_name;
            if (g_module_symbol(handle, "version", (gpointer*)&version) == FALSE)
@@ -426,15 +446,85 @@ plugins_scan_dir(const char *dirname)
 void
 init_plugins()
 {
+    struct stat std_dir_stat, local_dir_stat, plugin_dir_stat;
+
     if (plugin_list == NULL)      /* ensure init_plugins is only run once */
     {
+       enabled_plugins_number = 0;
+
+#ifdef PLUGINS_NEED_ADDRESS_TABLE
+       /* Intialize address table */
+       patable.p_check_col                     = check_col;
+       patable.p_col_add_fstr                  = col_add_fstr;
+       patable.p_col_append_fstr               = col_append_str;
+       patable.p_col_add_str                   = col_add_str;
+       patable.p_col_append_str                = col_append_str;
+
+       patable.p_dfilter_init                  = dfilter_init;
+       patable.p_dfilter_cleanup               = dfilter_cleanup;
+
+       patable.p_pi                            = &pi;
+
+       patable.p_proto_register_protocol       = proto_register_protocol;
+       patable.p_proto_register_field_array    = proto_register_field_array;
+       patable.p_proto_register_subtree_array  = proto_register_subtree_array;
+
+       patable.p_dissector_add                 = dissector_add;
+
+       patable.p_heur_dissector_add            = heur_dissector_add;
+
+       patable.p_proto_item_add_subtree        = proto_item_add_subtree;
+       patable.p_proto_tree_add_item           = proto_tree_add_item;
+       patable.p_proto_tree_add_item_hidden    = proto_tree_add_item_hidden;
+       patable.p_proto_tree_add_protocol_format = proto_tree_add_protocol_format;
+       patable.p_proto_tree_add_bytes_format   = proto_tree_add_bytes_format;
+       patable.p_proto_tree_add_time_format    = proto_tree_add_time_format;
+       patable.p_proto_tree_add_ipxnet_format  = proto_tree_add_ipxnet_format;
+       patable.p_proto_tree_add_ipv4_format    = proto_tree_add_ipv4_format;
+       patable.p_proto_tree_add_ipv6_format    = proto_tree_add_ipv6_format;
+       patable.p_proto_tree_add_ether_format   = proto_tree_add_ether_format;
+       patable.p_proto_tree_add_string_format  = proto_tree_add_string_format;
+       patable.p_proto_tree_add_boolean_format = proto_tree_add_boolean_format;
+       patable.p_proto_tree_add_uint_format    = proto_tree_add_uint_format;
+       patable.p_proto_tree_add_text           = proto_tree_add_text;
+       patable.p_proto_tree_add_notext         = proto_tree_add_notext;
+#endif
+
        plugins_scan_dir(std_plug_dir);
        plugins_scan_dir(local_plug_dir);
-        if ((strcmp(std_plug_dir, PLUGIN_DIR) != 0) &&
-            (strcmp(local_plug_dir, PLUGIN_DIR) != 0))
-        {
-          plugins_scan_dir(PLUGIN_DIR);
-        }
+       if ((strcmp(std_plug_dir, PLUGIN_DIR) != 0) &&
+               (strcmp(local_plug_dir, PLUGIN_DIR) != 0))
+       {
+           if (stat(PLUGIN_DIR, &plugin_dir_stat) == 0)
+           {
+               /* check if PLUGIN_DIR is really different from std_dir and
+                * local_dir if they exist ! */
+               if (stat(std_plug_dir, &std_dir_stat) == 0)
+               {
+                   if (stat(local_plug_dir, &local_dir_stat) == 0)
+                   {
+                       if ((plugin_dir_stat.st_dev != std_dir_stat.st_dev ||
+                                   plugin_dir_stat.st_ino != std_dir_stat.st_ino) &&
+                               (plugin_dir_stat.st_dev != local_dir_stat.st_dev ||
+                                plugin_dir_stat.st_ino != local_dir_stat.st_ino))
+                           plugins_scan_dir(PLUGIN_DIR);
+                   }
+                   else
+                   {
+                       if ((plugin_dir_stat.st_dev != std_dir_stat.st_dev ||
+                                   plugin_dir_stat.st_ino != std_dir_stat.st_ino))
+                           plugins_scan_dir(PLUGIN_DIR);
+                   }
+               }
+               else if (stat(local_plug_dir, &local_dir_stat) == 0)
+               {
+                   if ((plugin_dir_stat.st_dev != local_dir_stat.st_dev ||
+                               plugin_dir_stat.st_ino != local_dir_stat.st_ino))
+                       plugins_scan_dir(PLUGIN_DIR);
+               }
+               else plugins_scan_dir(PLUGIN_DIR);
+           }
+       }
        if (!user_plug_dir)
        {
            user_plug_dir = (gchar *)g_malloc(strlen(get_home_dir()) + 19);