Move privileges.c and unicode-utils.c from epan to wsutil (so things like
[metze/wireshark/wip.git] / epan / plugins.c
index 929038215ccc6bf91d870f954c5d71abd1934022..ed8aaa3f8c2c199fb18a6e90304b6ab8e3175786 100644 (file)
@@ -1,23 +1,22 @@
 /* plugins.c
  * plugin routines
  *
- * $Id: plugins.c,v 1.25 2001/07/22 10:12:08 guy Exp $
+ * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1999 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.
@@ -27,7 +26,6 @@
 # include "config.h"
 #endif
 
-#include <epan.h>
 #include "plugins.h"
 
 #ifdef HAVE_PLUGINS
 
 #include <string.h>
 #include <stdlib.h>
-#include <errno.h> 
-
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
+#include <errno.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
 #include "filesystem.h"
-
-#include "prefs.h"
-
-#ifdef PLUGINS_NEED_ADDRESS_TABLE
-#include "packet-giop.h"
-#include "plugins/plugin_table.h"
-static plugin_address_table_t  patable;
-#endif
+#include <wsutil/privileges.h>
+#include <wsutil/file_util.h>
+#include "report_err.h"
 
 /* linked list of all plugins */
 plugin *plugin_list;
 
-#ifdef WIN32
-static gchar std_plug_dir[] = "c:/program files/ethereal/plugins/" VERSION;
-static gchar local_plug_dir[] = "c:/ethereal/plugins/" VERSION;
-#else
-static gchar std_plug_dir[] = "/usr/lib/ethereal/plugins/" VERSION;
-static gchar local_plug_dir[] = "/usr/local/lib/ethereal/plugins/" VERSION;
-#endif
-static gchar *user_plug_dir = NULL;
-
 #define PLUGINS_DIR_NAME       "plugins"
 
 /*
@@ -91,7 +67,10 @@ static gchar *user_plug_dir = NULL;
  */
 static int
 add_plugin(void *handle, gchar *name, gchar *version,
-          void (*reg_handoff)(void))
+          void (*register_protoinfo)(void), void (*reg_handoff)(void),
+          void (*register_tap_listener)(void),
+          void (*register_wtap_module)(void),
+          void (*register_codec_module)(void))
 {
     plugin *new_plug, *pt_plug;
 
@@ -126,8 +105,13 @@ add_plugin(void *handle, gchar *name, gchar *version,
     new_plug->handle = handle;
     new_plug->name = name;
     new_plug->version = version;
+    new_plug->register_protoinfo = register_protoinfo;
     new_plug->reg_handoff = reg_handoff;
+    new_plug->register_tap_listener = register_tap_listener;
+    new_plug->register_wtap_module = register_wtap_module;
+    new_plug->register_codec_module = register_codec_module;
     new_plug->next = NULL;
+
     return 0;
 }
 
@@ -148,339 +132,368 @@ static void
 plugins_scan_dir(const char *dirname)
 {
 #define FILENAME_LEN   1024
-    gchar         *hack_path;       /* pathname used to construct lt_lib_ext */
-    gchar         *lt_lib_ext;      /* extension for loadable modules */
-    DIR           *dir;             /* scanned directory */
-    struct dirent *file;            /* current file */
+    ETH_DIR       *dir;             /* scanned directory */
+    ETH_DIRENT    *file;            /* current file */
+    const char    *name;
     gchar          filename[FILENAME_LEN];   /* current file name */
     GModule       *handle;          /* handle returned by dlopen */
-    gchar         *name;
     gchar         *version;
-    void         (*init)(void *);
+    gpointer       gp;
+    void         (*register_protoinfo)(void);
     void         (*reg_handoff)(void);
+    void         (*register_tap_listener)(void);
+    void (*register_wtap_module)(void);
+    void (*register_codec_module)(void);
+
     gchar         *dot;
     int            cr;
 
-    /*
-     * We find the extension used on this platform for loadable modules
-     * by the sneaky hack of calling "g_module_build_path" to build
-     * the pathname for a module with an empty directory name and
-     * empty module name, and then search for the last "." and use
-     * everything from the last "." on.
-     *
-     * GLib 2.0 will probably define G_MODULE_SUFFIX as the extension
-     * to use, but that's not checked into the GLib CVS tree yet,
-     * and we can't use it on systems that don't have GLib 2.0.
-     */
-    hack_path = g_module_build_path("", "");
-    lt_lib_ext = strrchr(hack_path, '.');
-    if (lt_lib_ext == NULL)
+    if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL)
     {
-       /*
-        * Does this mean there *is* no extension?  Assume so.
-        *
-        * XXX - the code below assumes that all loadable modules have
-        * an extension....
-        */
-       lt_lib_ext = "";
-    }
 
-    if ((dir = opendir(dirname)) != NULL)
-    {
-       while ((file = readdir(dir)) != NULL)
+    while ((file = ws_dir_read_name(dir)) != NULL)
        {
-           /* don't try to open "." and ".." */
-           if (!(strcmp(file->d_name, "..") &&
-                 strcmp(file->d_name, "."))) continue;
-
-            /* skip anything but files with lt_lib_ext */
-            dot = strrchr(file->d_name, '.');
-            if (dot == NULL || strcmp(dot, lt_lib_ext) != 0) continue;
-
-           snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_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)
+           name = ws_dir_get_name(file);
+
+           /*
+            * GLib 2.x defines G_MODULE_SUFFIX as the extension used on
+            * this platform for loadable modules.
+            */
+           /* skip anything but files with G_MODULE_SUFFIX */
+            dot = strrchr(name, '.');
+            if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0)
+               continue;
+
+           g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
+               dirname, name);
+           if ((handle = g_module_open(filename, 0)) == NULL)
            {
-               g_warning("The plugin %s has no version symbol", name);
+               report_failure("Couldn't load module %s: %s", filename,
+                         g_module_error());
+               continue;
+           }
+
+           if (!g_module_symbol(handle, "version", &gp))
+           {
+               report_failure("The plugin %s has no version symbol", name);
                g_module_close(handle);
                continue;
            }
+           version = gp;
 
            /*
-            * Old-style dissectors don't have a "plugin_reg_handoff()"
-            * routine; we no longer support them.
-            *
-            * New-style dissectors have one, because, otherwise, there's
-            * no way for them to arrange that they ever be called.
+            * Do we have a register routine?
             */
-           if (g_module_symbol(handle, "plugin_reg_handoff",
-                                        (gpointer*)&reg_handoff))
+           if (g_module_symbol(handle, "plugin_register", &gp))
            {
                /*
-                * We require it to have a "plugin_init()" routine.
+                * Yes - this plugin includes one or more dissectors.
                 */
-               if (!g_module_symbol(handle, "plugin_init", (gpointer*)&init))
-               {
-                   g_warning("The plugin %s has a plugin_reg_handoff symbol but no plugin_init routine", name);
-                   g_module_close(handle);
-                   continue;
-               }
+               register_protoinfo = gp;
+           }
+           else
+           {
+               /*
+                * No - no dissectors.
+                */
+               register_protoinfo = NULL;
+           }
 
+           /*
+            * Do we have a reg_handoff routine?
+            */
+           if (g_module_symbol(handle, "plugin_reg_handoff", &gp))
+           {
                /*
-                * We have a "plugin_reg_handoff()" routine, so we don't
-                * need the protocol, filter string, or dissector pointer.
+                * Yes.
                 */
-               if ((cr = add_plugin(handle, g_strdup(file->d_name), version,
-                                    reg_handoff)))
-               {
-                   if (cr == EEXIST)
-                       fprintf(stderr, "The plugin %s, version %s\n"
-                           "was found in multiple directories\n", name, version);
-                   else
-                       fprintf(stderr, "Memory allocation problem\n"
-                           "when processing plugin %s, version %s\n",
-                           name, version);
-                   g_module_close(handle);
-                   continue;
-               }
+               reg_handoff = gp;
+           }
+           else
+           {
+               /*
+                * No - that's OK even if we have dissectors, as long
+                * as the plugin registers by name *and* there's
+                * a caller looking for that name.
+                */
+               reg_handoff = NULL;
+           }
 
+           /*
+            * Do we have a register_tap_listener routine?
+            */
+           if (g_module_symbol(handle, "plugin_register_tap_listener", &gp))
+           {
                /*
-                * Call its init routine.
+                * Yes - this plugin includes one or more taps.
                 */
-#ifdef PLUGINS_NEED_ADDRESS_TABLE
-               init(&patable);
-#else
-               init(NULL);
-#endif
+               register_tap_listener = gp;
            }
            else
            {
                /*
-                * This is an old-style dissector; warn that it won't
-                * be used, as those aren't supported.
+                * No - no taps here.
+                */
+               register_tap_listener = NULL;
+           }
+
+               /*
+            * Do we have an old-style init routine?
+            */
+           if (g_module_symbol(handle, "plugin_init", &gp))
+           {
+                       /*
+                        * Yes - do we also have a register routine or a
+                        * register_tap_listener routine?  If so, this is a bogus
+                        * hybrid of an old-style and new-style plugin.
+                        */
+                       if (register_protoinfo != NULL || register_tap_listener != NULL)
+                       {
+                               report_failure("The plugin '%s' has an old plugin init routine\nand a new register or register_tap_listener routine.",
+                               name);
+                               g_module_close(handle);
+                               continue;
+                       }
+
+                       /*
+                        * It's just an unsupported old-style plugin;
+                        */
+                       report_failure("The plugin '%s' has an old plugin init routine. Support has been dropped.\n Information on how to update your plugin is available at \nhttp://anonsvn.wireshark.org/wireshark/trunk/doc/README.plugins",
+                               name);
+                       g_module_close(handle);
+                       continue;
+           }
+
+           /*
+                * Do we have a register_wtap_module routine?
+                */
+           if (g_module_symbol(handle, "register_wtap_module", &gp))
+           {
+               register_wtap_module = gp;
+           } else {
+               register_wtap_module = NULL;
+           }
+
+           /*
+                * Do we have a register_codec_module routine?
+                */
+           if (g_module_symbol(handle, "register_codec_module", &gp))
+           {
+               register_codec_module = gp;
+           } else {
+               register_codec_module = NULL;
+           }
+
+          /*
+               * Does this dissector do anything useful?
+               */
+           if (register_protoinfo == NULL &&
+                   register_tap_listener == NULL &&
+                   register_wtap_module == NULL &&
+                   register_codec_module == NULL )
+           {
+               /*
+                * No.
                 */
-               fprintf(stderr,
-                   "The plugin %s, version %s is an old-style plugin;\n"
-                   "Those are no longer supported.\n", name, version);
+               report_failure("The plugin '%s' has neither a register routine, "
+                                          "a register_tap_listener or a register_wtap_module or a register_codec_module routine",
+                   name);
+               g_module_close(handle);
+               continue;
            }
+
+           /*
+            * OK, attempt to add it to the list of plugins.
+            */
+           if ((cr = add_plugin(handle, g_strdup(name), version,
+                                register_protoinfo, reg_handoff,
+                                register_tap_listener,register_wtap_module,register_codec_module)))
+           {
+               if (cr == EEXIST)
+                   fprintf(stderr, "The plugin %s, version %s\n"
+                           "was found in multiple directories\n", name, version);
+               else
+                   fprintf(stderr, "Memory allocation problem\n"
+                           "when processing plugin %s, version %s\n",
+                           name, version);
+               g_module_close(handle);
+               continue;
+           }
+
        }
-       closedir(dir);
-    }
-    g_free(hack_path);
+       ws_dir_close(dir);
+       }
+}
+
+/* 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
  */
 void
-init_plugins(const char *plugin_dir)
+init_plugins(void)
 {
-    struct stat std_dir_stat, local_dir_stat, plugin_dir_stat;
+    const char *plugin_dir;
+    const char *name;
+    char *plugin_dir_path;
+    char *plugins_pers_dir;
+    ETH_DIR *dir;              /* scanned directory */
+    ETH_DIRENT *file;          /* current file */
 
     if (plugin_list == NULL)      /* ensure init_plugins is only run once */
     {
-#ifdef PLUGINS_NEED_ADDRESS_TABLE
-       /* Intialize address table */
-       patable.p_check_col                     = check_col;
-       patable.p_col_clear                     = col_clear;
-       patable.p_col_add_fstr                  = col_add_fstr;
-       patable.p_col_append_fstr               = col_append_fstr;
-       patable.p_col_add_str                   = col_add_str;
-       patable.p_col_append_str                = col_append_str;
-       patable.p_col_set_str                   = col_set_str;
-
-       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_dissector_delete              = dissector_delete;
-
-       patable.p_heur_dissector_add            = heur_dissector_add;
-
-       patable.p_register_dissector            = register_dissector;
-       patable.p_find_dissector                = find_dissector;
-       patable.p_call_dissector                = call_dissector;
-
-       patable.p_dissect_data                  = dissect_data;
-
-       patable.p_proto_is_protocol_enabled     = proto_is_protocol_enabled;
-
-       patable.p_proto_item_get_len            = proto_item_get_len;
-       patable.p_proto_item_set_len            = proto_item_set_len;
-       patable.p_proto_item_set_text           = proto_item_set_text;
-       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          = proto_tree_add_bytes;
-       patable.p_proto_tree_add_bytes_hidden   = proto_tree_add_bytes_hidden;
-       patable.p_proto_tree_add_bytes_format   = proto_tree_add_bytes_format;
-       patable.p_proto_tree_add_time           = proto_tree_add_time;
-       patable.p_proto_tree_add_time_hidden    = proto_tree_add_time_hidden;
-       patable.p_proto_tree_add_time_format    = proto_tree_add_time_format;
-       patable.p_proto_tree_add_ipxnet         = proto_tree_add_ipxnet;
-       patable.p_proto_tree_add_ipxnet_hidden  = proto_tree_add_ipxnet_hidden;
-       patable.p_proto_tree_add_ipxnet_format  = proto_tree_add_ipxnet_format;
-       patable.p_proto_tree_add_ipv4           = proto_tree_add_ipv4;
-       patable.p_proto_tree_add_ipv4_hidden    = proto_tree_add_ipv4_hidden;
-       patable.p_proto_tree_add_ipv4_format    = proto_tree_add_ipv4_format;
-       patable.p_proto_tree_add_ipv6           = proto_tree_add_ipv6;
-       patable.p_proto_tree_add_ipv6_hidden    = proto_tree_add_ipv6_hidden;
-       patable.p_proto_tree_add_ipv6_format    = proto_tree_add_ipv6_format;
-       patable.p_proto_tree_add_ether          = proto_tree_add_ether;
-       patable.p_proto_tree_add_ether_hidden   = proto_tree_add_ether_hidden;
-       patable.p_proto_tree_add_ether_format   = proto_tree_add_ether_format;
-       patable.p_proto_tree_add_string         = proto_tree_add_string;
-       patable.p_proto_tree_add_string_hidden  = proto_tree_add_string_hidden;
-       patable.p_proto_tree_add_string_format  = proto_tree_add_string_format;
-       patable.p_proto_tree_add_boolean        = proto_tree_add_boolean;
-       patable.p_proto_tree_add_boolean_hidden = proto_tree_add_boolean_hidden;
-       patable.p_proto_tree_add_boolean_format = proto_tree_add_boolean_format;
-       patable.p_proto_tree_add_double         = proto_tree_add_double;
-       patable.p_proto_tree_add_double_hidden  = proto_tree_add_double_hidden;
-       patable.p_proto_tree_add_double_format  = proto_tree_add_double_format;
-       patable.p_proto_tree_add_uint           = proto_tree_add_uint;
-       patable.p_proto_tree_add_uint_hidden    = proto_tree_add_uint_hidden;
-       patable.p_proto_tree_add_uint_format    = proto_tree_add_uint_format;
-       patable.p_proto_tree_add_int            = proto_tree_add_int;
-       patable.p_proto_tree_add_int_hidden     = proto_tree_add_int_hidden;
-       patable.p_proto_tree_add_int_format     = proto_tree_add_int_format;
-       patable.p_proto_tree_add_text           = proto_tree_add_text;
-       patable.p_proto_tree_add_notext         = proto_tree_add_notext;
-
-       patable.p_tvb_new_subset                = tvb_new_subset;
-
-       patable.p_tvb_length                    = tvb_length;
-       patable.p_tvb_length_remaining          = tvb_length_remaining;
-       patable.p_tvb_bytes_exist               = tvb_bytes_exist;
-       patable.p_tvb_offset_exists             = tvb_offset_exists;
-       patable.p_tvb_reported_length           = tvb_reported_length;
-       patable.p_tvb_reported_length_remaining = tvb_reported_length_remaining;
-
-       patable.p_tvb_get_guint8                = tvb_get_guint8;
-
-       patable.p_tvb_get_ntohs                 = tvb_get_ntohs;
-       patable.p_tvb_get_ntoh24                = tvb_get_ntoh24;
-       patable.p_tvb_get_ntohl                 = tvb_get_ntohl;
-#ifdef G_HAVE_GINT64
-       patable.p_tvb_get_ntohll                = tvb_get_ntohll;
-#endif
-
-       patable.p_tvb_get_letohs                = tvb_get_letohs;
-       patable.p_tvb_get_letoh24               = tvb_get_letoh24;
-       patable.p_tvb_get_letohl                = tvb_get_letohl;
-#ifdef G_HAVE_GINT64
-       patable.p_tvb_get_letohll               = tvb_get_letohll;
-#endif
-
-       patable.p_tvb_memcpy                    = tvb_memcpy;
-       patable.p_tvb_memdup                    = tvb_memdup;
-
-       patable.p_tvb_get_ptr                   = tvb_get_ptr;
-
-       patable.p_tvb_find_guint8               = tvb_find_guint8;
-       patable.p_tvb_pbrk_guint8               = tvb_pbrk_guint8;
+       /*
+        * Scan the global plugin directory.
+        * If we're running from a build directory, scan the subdirectories
+        * of that directory, as the global plugin directory is the
+        * "plugins" directory of the source tree, and the subdirectories
+        * are the source directories for the plugins, with the plugins
+        * built in those subdirectories.
+        */
+       plugin_dir = get_plugin_dir();
+       if (running_in_build_directory()) {
+           if ((dir = ws_dir_open(plugin_dir, 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 ".." */
+                   /*
+                    * Get the full path of a ".libs" subdirectory of that
+                    * directory.
+                    */
+                   plugin_dir_path = g_strdup_printf(
+                       "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S ".libs",
+                       plugin_dir, name);
+                   if (test_for_directory(plugin_dir_path) != EISDIR) {
+                       /*
+                        * Either it doesn't refer to a directory or it
+                        * refers to something that doesn't exist.
+                        *
+                        * Assume that means that the plugins are in
+                        * the subdirectory of the plugin directory, not
+                        * a ".libs" subdirectory of that subdirectory.
+                        */
+                       g_free(plugin_dir_path);
+                       plugin_dir_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
+                           plugin_dir, name);
+                   }
+                   plugins_scan_dir(plugin_dir_path);
+                   g_free(plugin_dir_path);
+               }
+           }
+       } else
+           plugins_scan_dir(plugin_dir);
 
-       patable.p_tvb_strnlen                   = tvb_strnlen;
+       /*
+        * If the program wasn't started with special privileges,
+        * scan the users plugin directory.  (Even if we relinquish
+        * them, plugins aren't safe unless we've *permanently*
+        * relinquished them, and we can't do that in Wireshark as,
+        * if we need privileges to start capturing, we'd need to
+        * reclaim them before each time we start capturing.)
+        */
+       if (!started_with_special_privs()) {
+           plugins_pers_dir = get_plugins_pers_dir();
+           plugins_scan_dir(plugins_pers_dir);
+           g_free(plugins_pers_dir);
+       }
+    }
+       register_all_wiretap_modules();
+       register_all_codecs();
+}
 
-       patable.p_tvb_format_text               = tvb_format_text;
+void
+register_all_plugin_registrations(void)
+{
+    plugin *pt_plug;
 
-       patable.p_tvb_get_nstringz              = tvb_get_nstringz;
-       patable.p_tvb_get_nstringz0             = tvb_get_nstringz0;
+    /*
+     * For all plugins with register-handoff routines, call the routines.
+     * This is called from "proto_init()"; it must be called after
+     * "register_all_protocols()" and "init_plugins()" are called,
+     * in case one plugin registers itself either with a built-in
+     * dissector or with another plugin; we must first register all
+     * dissectors, whether built-in or plugin, so their dissector tables
+     * are initialized, and only then register all handoffs.
+     */
+    for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
+    {
+               if (pt_plug->register_protoinfo)
+                       (pt_plug->register_protoinfo)();
+    }
+}
 
-       patable.p_tvb_find_line_end             = tvb_find_line_end;
-       patable.p_tvb_find_line_end_unquoted    = tvb_find_line_end_unquoted;
+void
+register_all_plugin_handoffs(void)
+{
+    plugin *pt_plug;
 
-       patable.p_tvb_strneql                   = tvb_strneql;
-       patable.p_tvb_strncaseeql               = tvb_strncaseeql;
+    /*
+     * For all plugins with register-handoff routines, call the routines.
+     * This is called from "proto_init()"; it must be called after
+     * "register_all_protocols()" and "init_plugins()" are called,
+     * in case one plugin registers itself either with a built-in
+     * dissector or with another plugin; we must first register all
+     * dissectors, whether built-in or plugin, so their dissector tables
+     * are initialized, and only then register all handoffs.
+     */
+    for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
+    {
+       if (pt_plug->reg_handoff)
+           (pt_plug->reg_handoff)();
+    }
+}
 
-       patable.p_tvb_bytes_to_str              = tvb_bytes_to_str;
+void
+register_all_plugin_tap_listeners(void)
+{
+    plugin *pt_plug;
 
-       patable.p_prefs_register_protocol       = prefs_register_protocol;
-       patable.p_prefs_register_uint_preference = prefs_register_uint_preference;
-       patable.p_prefs_register_bool_preference = prefs_register_bool_preference;
-       patable.p_prefs_register_enum_preference = prefs_register_enum_preference;
+    /*
+     * For all plugins with register-tap-listener routines, call the
+     * routines.
+     */
+    for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
+    {
+       if (pt_plug->register_tap_listener)
+           (pt_plug->register_tap_listener)();
+    }
+}
 
-       patable.p_register_giop_user            = register_giop_user;
-       patable.p_is_big_endian                 = is_big_endian;
-       patable.p_get_CDR_string                = get_CDR_string;
-       patable.p_get_CDR_ulong                 = get_CDR_ulong;
-       patable.p_get_CDR_enum                  = get_CDR_enum;
-       patable.p_get_CDR_object                = get_CDR_object;
-       patable.p_get_CDR_boolean               = get_CDR_boolean;
-#endif
+void
+register_all_wiretap_modules(void)
+{
+    plugin *pt_plug;
 
-       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))
-       {
-           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()) +
-                                             strlen(PF_DIR) +
-                                             strlen(PLUGINS_DIR_NAME) + 3);
-           sprintf(user_plug_dir, "%s/%s/%s", get_home_dir(), 
-                   PF_DIR, PLUGINS_DIR_NAME);
-       }
-       plugins_scan_dir(user_plug_dir);
+    /*
+     * For all plugins with register_wtap_module routines, call the
+     * routines.
+     */
+    for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
+    {
+               if (pt_plug->register_wtap_module)
+                       (pt_plug->register_wtap_module)();
     }
 }
 
 void
-register_all_plugin_handoffs(void)
+register_all_codecs(void)
 {
-  plugin *pt_plug;
-
-  /*
-   * For all new-style plugins, call the register-handoff routine.
-   * This is called from "proto_init()"; it must be called after
-   * "register_all_protocols()" and "init_plugins()" are called,
-   * in case one plugin registers itself either with a built-in
-   * dissector or with another plugin; we must first register all
-   * dissectors, whether built-in or plugin, so their dissector tables
-   * are initialized, and only then register all handoffs.
-   *
-   * We treat those protocols as always being enabled; they should
-   * use the standard mechanism for enabling/disabling protocols, not
-   * the plugin-specific mechanism.
-   */
-  for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
-    (pt_plug->reg_handoff)();
+    plugin *pt_plug;
+
+    /*
+     * For all plugins with register_wtap_module routines, call the
+     * routines.
+     */
+    for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
+    {
+               if (pt_plug->register_codec_module)
+                       (pt_plug->register_codec_module)();
+    }
 }
 #endif