1999-12-09 20:43:38 +00:00
/* plugins.c
1999-12-09 20:55:49 +00:00
* plugin routines
*
2004-07-18 00:24:25 +00:00
* $ Id $
1999-12-09 20:43:38 +00:00
*
2006-05-21 05:12:17 +00:00
* Wireshark - Network traffic analyzer
* By Gerald Combs < gerald @ wireshark . org >
1999-12-09 20:55:49 +00:00
* Copyright 1999 Gerald Combs
2002-08-28 20:41:00 +00:00
*
1999-12-09 20:43:38 +00:00
* 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 .
2002-08-28 20:41:00 +00:00
*
1999-12-09 20:43:38 +00:00
* 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 .
2002-08-28 20:41:00 +00:00
*
1999-12-09 20:43:38 +00:00
* 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 .
*/
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
2000-01-15 00:23:13 +00:00
# include "plugins.h"
# ifdef HAVE_PLUGINS
1999-12-09 20:43:38 +00:00
# include <time.h>
2000-01-15 00:23:13 +00:00
# ifdef HAVE_DIRENT_H
2000-01-04 20:37:18 +00:00
# include <dirent.h>
2000-01-15 00:23:13 +00:00
# endif
# ifdef HAVE_DIRECT_H
# include <direct.h>
# endif
2000-01-04 20:37:18 +00:00
# include <string.h>
2000-01-15 00:23:13 +00:00
# include <stdlib.h>
2002-08-28 20:41:00 +00:00
# include <errno.h>
2000-08-11 13:37:21 +00:00
2000-01-15 00:23:13 +00:00
# ifdef HAVE_UNISTD_H
2000-01-04 21:29:43 +00:00
# include <unistd.h>
2000-01-15 00:23:13 +00:00
# endif
1999-12-09 20:43:38 +00:00
2000-09-28 03:16:29 +00:00
# include "filesystem.h"
2006-02-06 03:11:34 +00:00
# include "privileges.h"
2005-11-07 02:47:09 +00:00
# include <wiretap/file_util.h>
2005-03-06 04:41:42 +00:00
# include "report_err.h"
1999-12-09 20:43:38 +00:00
/* linked list of all plugins */
plugin * plugin_list ;
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
2000-08-19 17:53:02 +00:00
# define PLUGINS_DIR_NAME "plugins"
1999-12-09 20:43:38 +00:00
/*
* add a new plugin to the list
* returns :
* - 0 : OK
* - ENOMEM : memory allocation problem
* - EEXIST : the same plugin ( i . e . name / version ) was already registered .
*/
2001-01-28 21:17:29 +00:00
static int
add_plugin ( void * handle , gchar * name , gchar * version ,
2005-03-07 02:44:41 +00:00
void ( * register_protoinfo ) ( void ) , void ( * reg_handoff ) ( void ) ,
2007-05-24 22:26:51 +00:00
void ( * register_tap_listener ) ( void ) ,
2007-10-25 09:38:15 +00:00
void ( * register_wtap_module ) ( void ) ,
void ( * register_codec_module ) ( void ) )
1999-12-09 20:43:38 +00:00
{
plugin * new_plug , * pt_plug ;
pt_plug = plugin_list ;
if ( ! pt_plug ) /* the list is empty */
{
new_plug = ( plugin * ) g_malloc ( sizeof ( plugin ) ) ;
if ( new_plug = = NULL ) return ENOMEM ;
plugin_list = new_plug ;
}
else
{
while ( 1 )
{
/* check if the same name/version is already registered */
if ( ! strcmp ( pt_plug - > name , name ) & &
! strcmp ( pt_plug - > version , version ) )
{
return EEXIST ;
}
/* we found the last plugin in the list */
if ( pt_plug - > next = = NULL ) break ;
pt_plug = pt_plug - > next ;
}
new_plug = ( plugin * ) g_malloc ( sizeof ( plugin ) ) ;
if ( new_plug = = NULL ) return ENOMEM ;
pt_plug - > next = new_plug ;
}
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
new_plug - > handle = handle ;
new_plug - > name = name ;
new_plug - > version = version ;
2005-03-07 02:44:41 +00:00
new_plug - > register_protoinfo = register_protoinfo ;
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
new_plug - > reg_handoff = reg_handoff ;
2005-02-27 22:04:48 +00:00
new_plug - > register_tap_listener = register_tap_listener ;
2007-05-24 22:26:51 +00:00
new_plug - > register_wtap_module = register_wtap_module ;
2007-10-25 09:38:15 +00:00
new_plug - > register_codec_module = register_codec_module ;
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
new_plug - > next = NULL ;
2007-05-24 22:26:51 +00:00
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
return 0 ;
}
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we
call the initialization routines for built-in dissectors, but don't call
their handoff registration routines yet, and then call the handoff
registration routines right after calling the handoff registration
routines for built-in dissectors.
Do all that in "proto_init()", rather than "epan_init()".
That way, we call all dissector registration routines together, and then
call all dissector handoff registration routines together; all the
registration routines are called before any handoff registration
routines, as is required, and, as "proto_init()" is called by
"epan_init()" before "dfilter_init()" is called, all filterable fields
have been registered before "dfilter_init()" is called, and no plugins
have to call "dfilter_init()" themselves to get their fields registered.
Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the
plugin address table, as plugins shouldn't be calling them any more, and
remove calls to them from plugins.
svn path=/trunk/; revision=2940
2001-01-26 06:14:53 +00:00
/*
* XXX - when we remove support for old - style plugins ( which we should
* probably do eventually , as all plugins should be written as new - style
* ones ) , we may want to have " init_plugins() " merely save a pointer
* to the plugin ' s " init " routine , just as we save a pointer to its
* " reg_handoff " routine , and have a " register_all_plugins() " routine
* to go through the list of plugins and call all of them .
*
* Then we ' d have " epan_init() " , or perhaps even something higher up
* in the call tree , call " init_plugins() " , and have " proto_init() "
* call " register_all_plugins() " right after calling " register_all_protocols() " ;
* this might be a bit cleaner .
*/
2000-01-04 20:37:18 +00:00
static void
plugins_scan_dir ( const char * dirname )
{
2000-08-19 17:53:02 +00:00
# define FILENAME_LEN 1024
2005-11-06 22:43:25 +00:00
ETH_DIR * dir ; /* scanned directory */
ETH_DIRENT * file ; /* current file */
const char * name ;
2003-06-03 02:32:56 +00:00
# if GLIB_MAJOR_VERSION < 2
2000-11-29 09:10:03 +00:00
gchar * hack_path ; /* pathname used to construct lt_lib_ext */
gchar * lt_lib_ext ; /* extension for loadable modules */
2003-06-03 02:32:56 +00:00
# endif
2000-08-19 17:53:02 +00:00
gchar filename [ FILENAME_LEN ] ; /* current file name */
2000-01-15 00:23:13 +00:00
GModule * handle ; /* handle returned by dlopen */
2000-01-04 20:37:18 +00:00
gchar * version ;
2005-01-02 04:01:00 +00:00
gpointer gp ;
2005-03-07 02:44:41 +00:00
void ( * register_protoinfo ) ( void ) ;
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
void ( * reg_handoff ) ( void ) ;
2005-02-27 22:04:48 +00:00
void ( * register_tap_listener ) ( void ) ;
2007-05-24 22:26:51 +00:00
void ( * register_wtap_module ) ( void ) ;
2007-10-25 09:38:15 +00:00
void ( * register_codec_module ) ( void ) ;
2007-05-24 22:26:51 +00:00
2000-01-04 20:37:18 +00:00
gchar * dot ;
int cr ;
2003-06-04 00:11:02 +00:00
# if GLIB_MAJOR_VERSION < 2
2000-11-29 09:10:03 +00:00
/*
* 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 .
*/
hack_path = g_module_build_path ( " " , " " ) ;
lt_lib_ext = strrchr ( hack_path , ' . ' ) ;
if ( lt_lib_ext = = 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 = " " ;
}
2005-11-06 22:43:25 +00:00
# endif
2000-01-04 20:37:18 +00:00
2005-11-07 08:36:25 +00:00
if ( ( dir = eth_dir_open ( dirname , 0 , NULL ) ) ! = NULL )
2000-01-04 20:37:18 +00:00
{
2007-05-25 17:22:32 +00:00
2005-11-06 22:43:25 +00:00
while ( ( file = eth_dir_read_name ( dir ) ) ! = NULL )
2000-01-04 20:37:18 +00:00
{
2005-11-06 22:43:25 +00:00
name = eth_dir_get_name ( file ) ;
2007-05-24 22:26:51 +00:00
2005-11-06 22:43:25 +00:00
# if GLIB_MAJOR_VERSION < 2
2000-01-04 20:37:18 +00:00
/* don't try to open "." and ".." */
2005-11-06 22:43:25 +00:00
if ( ! ( strcmp ( name , " .. " ) & &
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
strcmp ( name , " . " ) ) )
continue ;
2000-01-04 20:37:18 +00:00
2000-11-29 09:10:03 +00:00
/* skip anything but files with lt_lib_ext */
2005-11-06 22:43:25 +00:00
dot = strrchr ( name , ' . ' ) ;
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
if ( dot = = NULL | | strcmp ( dot , lt_lib_ext ) ! = 0 )
continue ;
2000-01-04 20:37:18 +00:00
2003-06-03 02:32:56 +00:00
# else /* GLIB 2 */
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
/*
* GLib 2. x defines G_MODULE_SUFFIX as the extension used on
* this platform for loadable modules .
*/
2003-06-03 02:32:56 +00:00
/* skip anything but files with G_MODULE_SUFFIX */
dot = strrchr ( name , ' . ' ) ;
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
if ( dot = = NULL | | strcmp ( dot + 1 , G_MODULE_SUFFIX ) ! = 0 )
continue ;
2003-06-03 02:32:56 +00:00
2005-11-06 22:43:25 +00:00
# endif
2005-08-08 18:50:39 +00:00
g_snprintf ( filename , FILENAME_LEN , " %s " G_DIR_SEPARATOR_S " %s " ,
2003-06-03 02:32:56 +00:00
dirname , name ) ;
if ( ( handle = g_module_open ( filename , 0 ) ) = = NULL )
{
2005-03-05 06:28:10 +00:00
report_failure ( " Couldn't load module %s: %s " , filename ,
2003-06-03 02:32:56 +00:00
g_module_error ( ) ) ;
continue ;
}
2007-05-24 22:26:51 +00:00
2005-01-02 04:01:00 +00:00
if ( ! g_module_symbol ( handle , " version " , & gp ) )
2000-01-04 20:37:18 +00:00
{
2005-03-05 06:28:10 +00:00
report_failure ( " The plugin %s has no version symbol " , name ) ;
2000-01-15 00:23:13 +00:00
g_module_close ( handle ) ;
2000-01-04 20:37:18 +00:00
continue ;
}
2005-01-02 04:01:00 +00:00
version = gp ;
2005-03-05 06:28:10 +00:00
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
/*
2005-03-07 02:44:41 +00:00
* Do we have a register routine ?
2005-02-27 22:04:48 +00:00
*/
2005-03-07 02:44:41 +00:00
if ( g_module_symbol ( handle , " plugin_register " , & gp ) )
2005-02-27 22:04:48 +00:00
{
2005-03-07 02:44:41 +00:00
/*
* Yes - this plugin includes one or more dissectors .
*/
register_protoinfo = gp ;
2005-03-06 04:41:42 +00:00
}
2005-03-07 02:44:41 +00:00
else
2005-03-05 06:28:10 +00:00
{
2005-03-07 02:44:41 +00:00
/*
* No - no dissectors .
*/
register_protoinfo = NULL ;
2005-02-27 22:04:48 +00:00
}
/*
* Do we have a reg_handoff routine ?
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
*/
2005-01-02 04:01:00 +00:00
if ( g_module_symbol ( handle , " plugin_reg_handoff " , & gp ) )
2000-01-04 20:37:18 +00:00
{
2005-02-27 22:04:48 +00:00
/*
2005-03-07 02:44:41 +00:00
* Yes .
2005-02-27 22:04:48 +00:00
*/
2005-01-02 04:01:00 +00:00
reg_handoff = gp ;
2005-02-27 22:04:48 +00:00
}
else
{
/*
2005-03-07 02:44:41 +00:00
* 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 .
2005-02-27 22:04:48 +00:00
*/
reg_handoff = NULL ;
}
2005-01-02 04:01:00 +00:00
2005-02-27 22:04:48 +00:00
/*
* Do we have a register_tap_listener routine ?
*/
if ( g_module_symbol ( handle , " plugin_register_tap_listener " , & gp ) )
{
/*
* Yes - this plugin includes one or more taps .
*/
register_tap_listener = gp ;
}
else
{
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
/*
2005-02-27 22:04:48 +00:00
* No - no taps here .
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
*/
2005-02-27 22:04:48 +00:00
register_tap_listener = NULL ;
}
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
2007-05-24 22:26:51 +00:00
/*
2005-03-16 23:07:08 +00:00
* Do we have an old - style init routine ?
2005-03-07 02:44:41 +00:00
*/
if ( g_module_symbol ( handle , " plugin_init " , & gp ) )
{
2007-05-24 22:26:51 +00:00
/*
* 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 \n and a new register or register_tap_listener routine. " ,
name ) ;
g_module_close ( handle ) ;
continue ;
}
2005-03-07 02:44:41 +00:00
2007-05-24 22:26:51 +00:00
/*
* 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 \n http://anonsvn.wireshark.org/wireshark/trunk/doc/README.plugins " ,
name ) ;
g_module_close ( handle ) ;
continue ;
2005-03-07 02:44:41 +00:00
}
2007-05-24 22:26:51 +00:00
2005-02-27 22:04:48 +00:00
/*
2007-05-24 22:26:51 +00:00
* 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 ;
}
2007-10-25 09:38:15 +00:00
/*
* 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 ;
}
2007-05-24 22:26:51 +00:00
/*
* Does this dissector do anything useful ?
*/
2005-03-16 23:07:08 +00:00
if ( register_protoinfo = = NULL & &
2007-05-24 22:26:51 +00:00
register_tap_listener = = NULL & &
2007-10-25 09:38:15 +00:00
register_wtap_module = = NULL & &
register_codec_module = = NULL )
2005-02-27 22:04:48 +00:00
{
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
/*
2005-02-27 22:04:48 +00:00
* No .
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
*/
2007-05-24 22:26:51 +00:00
report_failure ( " The plugin '%s' has neither a register routine, "
2007-10-25 09:38:15 +00:00
" a register_tap_listener or a register_wtap_module or a register_codec_module routine " ,
2005-03-07 02:44:41 +00:00
name ) ;
2005-02-27 22:04:48 +00:00
g_module_close ( handle ) ;
continue ;
}
/*
* OK , attempt to add it to the list of plugins .
*/
if ( ( cr = add_plugin ( handle , g_strdup ( name ) , version ,
2005-03-07 02:44:41 +00:00
register_protoinfo , reg_handoff ,
2007-10-25 09:38:15 +00:00
register_tap_listener , register_wtap_module , register_codec_module ) ) )
2005-02-27 22:04:48 +00:00
{
if ( cr = = EEXIST )
fprintf ( stderr , " The plugin %s, version %s \n "
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
" was found in multiple directories \n " , name , version ) ;
2005-02-27 22:04:48 +00:00
else
fprintf ( stderr , " Memory allocation problem \n "
2001-01-28 21:17:29 +00:00
" when processing plugin %s, version %s \n " ,
Allow plugins to have, instead of "protocol" and "filter_string"
variables and a "dissector" routine, a "plugin_reg_handoff()" routine,
which will act just like the "reg_handoff()" routine of a non-plugin
dissector, registering the dissector with handoff tables.
This lets them plug into both TCP and UDP, or plug into protocols other
than TCP or UDP.
Those new-style plugin are enabled and disabled using the standard
"Edit->Protocols" mechanism (and thus should use
"OLD_CHECK_DISPLAY_AS_DATA()" or "CHECK_DISPLAY_AS_DATA()"); they don't
show up in the list of plugins, aren't enabled or disabled from that
list, and, as they don't have a filter, can't have the filter changed
from that list - instead, they should register preferences for port
numbers and the like if they should be configurable to use different
ports.
Make the Gryphon protocol a new-style plugin.
svn path=/trunk/; revision=2565
2000-11-05 09:05:00 +00:00
name , version ) ;
2005-02-27 22:04:48 +00:00
g_module_close ( handle ) ;
continue ;
}
2007-05-24 22:26:51 +00:00
2000-01-04 20:37:18 +00:00
}
2005-11-06 22:43:25 +00:00
eth_dir_close ( dir ) ;
}
2003-06-03 02:32:56 +00:00
# if GLIB_MAJOR_VERSION < 2
2000-11-29 09:10:03 +00:00
g_free ( hack_path ) ;
2003-06-03 02:32:56 +00:00
# endif
2000-01-04 20:37:18 +00:00
}
2004-05-20 13:48:25 +00:00
/* get the personal plugin dir */
/* Return value is malloced so the caller should g_free() it. */
2004-12-31 00:32:00 +00:00
char * get_plugins_pers_dir ( void )
2004-05-20 13:48:25 +00:00
{
2008-01-14 16:40:23 +00:00
return get_persconffile_path ( PLUGINS_DIR_NAME , FALSE , FALSE ) ;
2004-05-20 13:48:25 +00:00
}
/*
* init plugins
*/
void
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
init_plugins ( void )
2004-05-20 13:48:25 +00:00
{
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
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 */
2004-05-20 13:48:25 +00:00
if ( plugin_list = = NULL ) /* ensure init_plugins is only run once */
{
/*
* Scan the global plugin directory .
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
* 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 .
2004-05-20 13:48:25 +00:00
*/
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
plugin_dir = get_plugin_dir ( ) ;
if ( running_in_build_directory ( ) ) {
if ( ( dir = eth_dir_open ( plugin_dir , 0 , NULL ) ) ! = NULL ) {
while ( ( file = eth_dir_read_name ( dir ) ) ! = NULL ) {
name = eth_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 ) ;
2004-05-20 13:48:25 +00:00
/*
2006-02-06 03:11:34 +00:00
* 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 *
2006-05-22 08:14:01 +00:00
* relinquished them , and we can ' t do that in Wireshark as ,
2006-02-06 03:11:34 +00:00
* if we need privileges to start capturing , we ' d need to
* reclaim them before each time we start capturing . )
2004-05-20 13:48:25 +00:00
*/
2006-02-06 03:11:34 +00:00
if ( ! started_with_special_privs ( ) ) {
Add a WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment variable on UN*X;
if set, and if the program isn't running with additional privileges,
it'll treat the directory in which the program is found as the data
directory.
If, on Windows, the version-number subdirectory of {data
directory}\plugins doesn't exist (which is assumed to mean that the
program is being run from the build directory), or if, on UN*X,
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, the plugin directory is the
"plugins" subdirectory of the data directory, and all subdirectories of
that directory are scanned for plugins, as the "plugins" subdirectory of
the build directory contains subdirectories for the plugins; this means
that if we're running from the build directory, we'll find the plugins
we built in the build tree.
When generating the wireshark-filter man page, run tshark with
WIRESHARK_RUN_FROM_BUILD_DIRECTORY set, so it uses the plugins from the
build to generate the list of filters.
svn path=/trunk/; revision=20261
2007-01-02 06:49:40 +00:00
plugins_pers_dir = get_plugins_pers_dir ( ) ;
plugins_scan_dir ( plugins_pers_dir ) ;
g_free ( plugins_pers_dir ) ;
2006-02-06 03:11:34 +00:00
}
2000-01-04 20:37:18 +00:00
}
2007-08-07 20:07:43 +00:00
register_all_wiretap_modules ( ) ;
2007-10-25 09:38:15 +00:00
register_all_codecs ( ) ;
2000-01-04 20:37:18 +00:00
}
2007-05-25 17:22:32 +00:00
void
register_all_plugin_registrations ( void )
{
plugin * pt_plug ;
/*
* 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 ) ( ) ;
}
}
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we
call the initialization routines for built-in dissectors, but don't call
their handoff registration routines yet, and then call the handoff
registration routines right after calling the handoff registration
routines for built-in dissectors.
Do all that in "proto_init()", rather than "epan_init()".
That way, we call all dissector registration routines together, and then
call all dissector handoff registration routines together; all the
registration routines are called before any handoff registration
routines, as is required, and, as "proto_init()" is called by
"epan_init()" before "dfilter_init()" is called, all filterable fields
have been registered before "dfilter_init()" is called, and no plugins
have to call "dfilter_init()" themselves to get their fields registered.
Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the
plugin address table, as plugins shouldn't be calling them any more, and
remove calls to them from plugins.
svn path=/trunk/; revision=2940
2001-01-26 06:14:53 +00:00
void
register_all_plugin_handoffs ( void )
{
2005-02-27 22:04:48 +00:00
plugin * pt_plug ;
/*
* 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 ) ( ) ;
}
}
void
register_all_plugin_tap_listeners ( void )
{
plugin * pt_plug ;
/*
* 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 ) ( ) ;
}
Clean up the dissector registration up a bit - arrange that all plugins
be loaded and their initialization routines called in right after we
call the initialization routines for built-in dissectors, but don't call
their handoff registration routines yet, and then call the handoff
registration routines right after calling the handoff registration
routines for built-in dissectors.
Do all that in "proto_init()", rather than "epan_init()".
That way, we call all dissector registration routines together, and then
call all dissector handoff registration routines together; all the
registration routines are called before any handoff registration
routines, as is required, and, as "proto_init()" is called by
"epan_init()" before "dfilter_init()" is called, all filterable fields
have been registered before "dfilter_init()" is called, and no plugins
have to call "dfilter_init()" themselves to get their fields registered.
Remove pointers to "dfilter_init()" and "dfilter_cleanup()" from the
plugin address table, as plugins shouldn't be calling them any more, and
remove calls to them from plugins.
svn path=/trunk/; revision=2940
2001-01-26 06:14:53 +00:00
}
2007-05-24 22:26:51 +00:00
void
register_all_wiretap_modules ( void )
{
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_wtap_module )
( pt_plug - > register_wtap_module ) ( ) ;
}
}
2007-10-25 09:38:15 +00:00
void
register_all_codecs ( void )
{
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 ) ( ) ;
}
}
1999-12-09 20:43:38 +00:00
# endif