From Matthijs Melchior: don't export functions also implemented as
[obnox/wireshark/wip.git] / epan / plugins.c
1 /* plugins.c
2  * plugin routines
3  *
4  * $Id: plugins.c,v 1.70 2003/05/01 21:10:42 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1999 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #ifdef NEED_SNPRINTF_H
30 # include "snprintf.h"
31 #endif
32
33 #include "plugins.h"
34
35 #ifdef HAVE_PLUGINS
36
37 #include <time.h>
38
39 #ifdef HAVE_DIRENT_H
40 #include <dirent.h>
41 #endif
42
43 #ifdef HAVE_DIRECT_H
44 #include <direct.h>
45 #endif
46
47 #include <string.h>
48 #include <stdlib.h>
49 #include <errno.h>
50
51 #ifdef HAVE_SYS_STAT_H
52 #include <sys/stat.h>
53 #endif
54
55 #ifdef HAVE_UNISTD_H
56 #include <unistd.h>
57 #endif
58
59 #include "filesystem.h"
60
61 #ifdef PLUGINS_NEED_ADDRESS_TABLE
62 #include "conversation.h"
63 #include "reassemble.h"
64 #include "prefs.h"
65 #include "packet-giop.h"
66 #include "packet-tpkt.h"
67 #include "packet-tcp.h"
68 #include "tap.h"
69 #include "asn1.h"
70 #include "plugins/plugin_table.h"
71 static plugin_address_table_t   patable;
72 #endif
73
74 /* linked list of all plugins */
75 plugin *plugin_list;
76
77 static gchar *user_plug_dir = NULL;
78
79 #define PLUGINS_DIR_NAME        "plugins"
80
81 /*
82  * add a new plugin to the list
83  * returns :
84  * - 0 : OK
85  * - ENOMEM : memory allocation problem
86  * - EEXIST : the same plugin (i.e. name/version) was already registered.
87  */
88 static int
89 add_plugin(void *handle, gchar *name, gchar *version,
90            void (*reg_handoff)(void))
91 {
92     plugin *new_plug, *pt_plug;
93
94     pt_plug = plugin_list;
95     if (!pt_plug) /* the list is empty */
96     {
97         new_plug = (plugin *)g_malloc(sizeof(plugin));
98         if (new_plug == NULL) return ENOMEM;
99         plugin_list = new_plug;
100     }
101     else
102     {
103         while (1)
104         {
105             /* check if the same name/version is already registered */
106             if (!strcmp(pt_plug->name, name) &&
107                 !strcmp(pt_plug->version, version))
108             {
109                 return EEXIST;
110             }
111
112             /* we found the last plugin in the list */
113             if (pt_plug->next == NULL) break;
114
115             pt_plug = pt_plug->next;
116         }
117         new_plug = (plugin *)g_malloc(sizeof(plugin));
118         if (new_plug == NULL) return ENOMEM;
119         pt_plug->next = new_plug;
120     }
121
122     new_plug->handle = handle;
123     new_plug->name = name;
124     new_plug->version = version;
125     new_plug->reg_handoff = reg_handoff;
126     new_plug->next = NULL;
127     return 0;
128 }
129
130 /*
131  * XXX - when we remove support for old-style plugins (which we should
132  * probably do eventually, as all plugins should be written as new-style
133  * ones), we may want to have "init_plugins()" merely save a pointer
134  * to the plugin's "init" routine, just as we save a pointer to its
135  * "reg_handoff" routine, and have a "register_all_plugins()" routine
136  * to go through the list of plugins and call all of them.
137  *
138  * Then we'd have "epan_init()", or perhaps even something higher up
139  * in the call tree, call "init_plugins()", and have "proto_init()"
140  * call "register_all_plugins()" right after calling "register_all_protocols()";
141  * this might be a bit cleaner.
142  */
143 static void
144 plugins_scan_dir(const char *dirname)
145 {
146 #define FILENAME_LEN    1024
147     gchar         *hack_path;       /* pathname used to construct lt_lib_ext */
148     gchar         *lt_lib_ext;      /* extension for loadable modules */
149     DIR           *dir;             /* scanned directory */
150     struct dirent *file;            /* current file */
151     gchar          filename[FILENAME_LEN];   /* current file name */
152     GModule       *handle;          /* handle returned by dlopen */
153     gchar         *name;
154     gchar         *version;
155     void         (*init)(void *);
156     void         (*reg_handoff)(void);
157     gchar         *dot;
158     int            cr;
159
160     /*
161      * We find the extension used on this platform for loadable modules
162      * by the sneaky hack of calling "g_module_build_path" to build
163      * the pathname for a module with an empty directory name and
164      * empty module name, and then search for the last "." and use
165      * everything from the last "." on.
166      *
167      * GLib 2.0 will probably define G_MODULE_SUFFIX as the extension
168      * to use, but that's not checked into the GLib CVS tree yet,
169      * and we can't use it on systems that don't have GLib 2.0.
170      */
171     hack_path = g_module_build_path("", "");
172     lt_lib_ext = strrchr(hack_path, '.');
173     if (lt_lib_ext == NULL)
174     {
175         /*
176          * Does this mean there *is* no extension?  Assume so.
177          *
178          * XXX - the code below assumes that all loadable modules have
179          * an extension....
180          */
181         lt_lib_ext = "";
182     }
183
184     if ((dir = opendir(dirname)) != NULL)
185     {
186         while ((file = readdir(dir)) != NULL)
187         {
188             /* don't try to open "." and ".." */
189             if (!(strcmp(file->d_name, "..") &&
190                   strcmp(file->d_name, "."))) continue;
191
192             /* skip anything but files with lt_lib_ext */
193             dot = strrchr(file->d_name, '.');
194             if (dot == NULL || strcmp(dot, lt_lib_ext) != 0) continue;
195
196             snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
197                 dirname, file->d_name);
198             if ((handle = g_module_open(filename, 0)) == NULL)
199             {
200                 g_warning("Couldn't load module %s: %s", filename,
201                           g_module_error());
202                 continue;
203             }
204             name = (gchar *)file->d_name;
205             if (g_module_symbol(handle, "version", (gpointer*)&version) == FALSE)
206             {
207                 g_warning("The plugin %s has no version symbol", name);
208                 g_module_close(handle);
209                 continue;
210             }
211
212             /*
213              * Old-style dissectors don't have a "plugin_reg_handoff()"
214              * routine; we no longer support them.
215              *
216              * New-style dissectors have one, because, otherwise, there's
217              * no way for them to arrange that they ever be called.
218              */
219             if (g_module_symbol(handle, "plugin_reg_handoff",
220                                          (gpointer*)&reg_handoff))
221             {
222                 /*
223                  * We require it to have a "plugin_init()" routine.
224                  */
225                 if (!g_module_symbol(handle, "plugin_init", (gpointer*)&init))
226                 {
227                     g_warning("The plugin %s has a plugin_reg_handoff symbol but no plugin_init routine",
228                               name);
229                     g_module_close(handle);
230                     continue;
231                 }
232
233                 /*
234                  * We have a "plugin_reg_handoff()" routine, so we don't
235                  * need the protocol, filter string, or dissector pointer.
236                  */
237                 if ((cr = add_plugin(handle, g_strdup(file->d_name), version,
238                                      reg_handoff)))
239                 {
240                     if (cr == EEXIST)
241                         fprintf(stderr, "The plugin %s, version %s\n"
242                             "was found in multiple directories\n", name, version);
243                     else
244                         fprintf(stderr, "Memory allocation problem\n"
245                             "when processing plugin %s, version %s\n",
246                             name, version);
247                     g_module_close(handle);
248                     continue;
249                 }
250
251                 /*
252                  * Call its init routine.
253                  */
254 #ifdef PLUGINS_NEED_ADDRESS_TABLE
255                 init(&patable);
256 #else
257                 init(NULL);
258 #endif
259             }
260             else
261             {
262                 /*
263                  * This is an old-style dissector; warn that it won't
264                  * be used, as those aren't supported.
265                  */
266                 fprintf(stderr,
267                     "The plugin %s, version %s is an old-style plugin;\n"
268                     "Those are no longer supported.\n", name, version);
269             }
270         }
271         closedir(dir);
272     }
273     g_free(hack_path);
274 }
275
276 /*
277  * init plugins
278  */
279 void
280 init_plugins(const char *plugin_dir)
281 {
282 #ifdef WIN32
283     const char *datafile_dir;
284     char *install_plugin_dir;
285 #endif
286
287     if (plugin_list == NULL)      /* ensure init_plugins is only run once */
288     {
289 #ifdef PLUGINS_NEED_ADDRESS_TABLE
290         /* Intialize address table */
291         patable.p_check_col                     = check_col;
292         patable.p_col_clear                     = col_clear;
293         patable.p_col_add_fstr                  = col_add_fstr;
294         patable.p_col_append_fstr               = col_append_fstr;
295         patable.p_col_prepend_fstr              = col_prepend_fstr;
296         patable.p_col_add_str                   = col_add_str;
297         patable.p_col_append_str                = col_append_str;
298         patable.p_col_set_str                   = col_set_str;
299
300         patable.p_register_init_routine         = register_init_routine;
301         patable.p_register_postseq_cleanup_routine      = register_postseq_cleanup_routine;
302
303         patable.p_match_strval                  = match_strval;
304         patable.p_val_to_str                    = val_to_str;
305
306         patable.p_conversation_new              = conversation_new;
307         patable.p_find_conversation             = find_conversation;
308         patable.p_conversation_set_dissector    = conversation_set_dissector;
309
310         patable.p_proto_register_protocol       = proto_register_protocol;
311         patable.p_proto_register_field_array    = proto_register_field_array;
312         patable.p_proto_register_subtree_array  = proto_register_subtree_array;
313
314         patable.p_dissector_add                 = dissector_add;
315         patable.p_dissector_delete              = dissector_delete;
316         patable.p_dissector_add_handle          = dissector_add_handle;
317
318         patable.p_heur_dissector_add            = heur_dissector_add;
319
320         patable.p_register_dissector            = register_dissector;
321         patable.p_find_dissector                = find_dissector;
322         patable.p_create_dissector_handle       = create_dissector_handle;
323         patable.p_call_dissector                = call_dissector;
324
325         patable.p_tcp_dissect_pdus              = tcp_dissect_pdus;
326
327         patable.p_proto_is_protocol_enabled     = proto_is_protocol_enabled;
328
329         patable.p_proto_item_get_len            = proto_item_get_len;
330         patable.p_proto_item_set_len            = proto_item_set_len;
331         patable.p_proto_item_set_text           = proto_item_set_text;
332         patable.p_proto_item_append_text        = proto_item_append_text;
333         patable.p_proto_item_add_subtree        = proto_item_add_subtree;
334         patable.p_proto_tree_add_item           = proto_tree_add_item;
335         patable.p_proto_tree_add_item_hidden    = proto_tree_add_item_hidden;
336         patable.p_proto_tree_add_protocol_format = proto_tree_add_protocol_format;
337         patable.p_proto_tree_add_bytes          = proto_tree_add_bytes;
338         patable.p_proto_tree_add_bytes_hidden   = proto_tree_add_bytes_hidden;
339         patable.p_proto_tree_add_bytes_format   = proto_tree_add_bytes_format;
340         patable.p_proto_tree_add_time           = proto_tree_add_time;
341         patable.p_proto_tree_add_time_hidden    = proto_tree_add_time_hidden;
342         patable.p_proto_tree_add_time_format    = proto_tree_add_time_format;
343         patable.p_proto_tree_add_ipxnet         = proto_tree_add_ipxnet;
344         patable.p_proto_tree_add_ipxnet_hidden  = proto_tree_add_ipxnet_hidden;
345         patable.p_proto_tree_add_ipxnet_format  = proto_tree_add_ipxnet_format;
346         patable.p_proto_tree_add_ipv4           = proto_tree_add_ipv4;
347         patable.p_proto_tree_add_ipv4_hidden    = proto_tree_add_ipv4_hidden;
348         patable.p_proto_tree_add_ipv4_format    = proto_tree_add_ipv4_format;
349         patable.p_proto_tree_add_ipv6           = proto_tree_add_ipv6;
350         patable.p_proto_tree_add_ipv6_hidden    = proto_tree_add_ipv6_hidden;
351         patable.p_proto_tree_add_ipv6_format    = proto_tree_add_ipv6_format;
352         patable.p_proto_tree_add_ether          = proto_tree_add_ether;
353         patable.p_proto_tree_add_ether_hidden   = proto_tree_add_ether_hidden;
354         patable.p_proto_tree_add_ether_format   = proto_tree_add_ether_format;
355         patable.p_proto_tree_add_string         = proto_tree_add_string;
356         patable.p_proto_tree_add_string_hidden  = proto_tree_add_string_hidden;
357         patable.p_proto_tree_add_string_format  = proto_tree_add_string_format;
358         patable.p_proto_tree_add_boolean        = proto_tree_add_boolean;
359         patable.p_proto_tree_add_boolean_hidden = proto_tree_add_boolean_hidden;
360         patable.p_proto_tree_add_boolean_format = proto_tree_add_boolean_format;
361         patable.p_proto_tree_add_double         = proto_tree_add_double;
362         patable.p_proto_tree_add_double_hidden  = proto_tree_add_double_hidden;
363         patable.p_proto_tree_add_double_format  = proto_tree_add_double_format;
364         patable.p_proto_tree_add_uint           = proto_tree_add_uint;
365         patable.p_proto_tree_add_uint_hidden    = proto_tree_add_uint_hidden;
366         patable.p_proto_tree_add_uint_format    = proto_tree_add_uint_format;
367         patable.p_proto_tree_add_int            = proto_tree_add_int;
368         patable.p_proto_tree_add_int_hidden     = proto_tree_add_int_hidden;
369         patable.p_proto_tree_add_int_format     = proto_tree_add_int_format;
370         patable.p_proto_tree_add_text           = proto_tree_add_text;
371
372         patable.p_tvb_new_subset                = tvb_new_subset;
373         patable.p_tvb_set_free_cb               = tvb_set_free_cb;
374         patable.p_tvb_set_child_real_data_tvbuff = tvb_set_child_real_data_tvbuff;
375         patable.p_tvb_new_real_data             = tvb_new_real_data;
376
377         patable.p_tvb_length                    = tvb_length;
378         patable.p_tvb_length_remaining          = tvb_length_remaining;
379         patable.p_tvb_bytes_exist               = tvb_bytes_exist;
380         patable.p_tvb_offset_exists             = tvb_offset_exists;
381         patable.p_tvb_reported_length           = tvb_reported_length;
382         patable.p_tvb_reported_length_remaining = tvb_reported_length_remaining;
383
384         patable.p_tvb_get_guint8                = tvb_get_guint8;
385
386         patable.p_tvb_get_ntohs                 = tvb_get_ntohs;
387         patable.p_tvb_get_ntoh24                = tvb_get_ntoh24;
388         patable.p_tvb_get_ntohl                 = tvb_get_ntohl;
389
390         patable.p_tvb_get_letohs                = tvb_get_letohs;
391         patable.p_tvb_get_letoh24               = tvb_get_letoh24;
392         patable.p_tvb_get_letohl                = tvb_get_letohl;
393
394         patable.p_tvb_memcpy                    = tvb_memcpy;
395         patable.p_tvb_memdup                    = tvb_memdup;
396
397         patable.p_tvb_get_ptr                   = tvb_get_ptr;
398
399         patable.p_tvb_find_guint8               = tvb_find_guint8;
400         patable.p_tvb_pbrk_guint8               = tvb_pbrk_guint8;
401
402         patable.p_tvb_strnlen                   = tvb_strnlen;
403
404         patable.p_tvb_format_text               = tvb_format_text;
405
406         patable.p_tvb_get_nstringz              = tvb_get_nstringz;
407         patable.p_tvb_get_nstringz0             = tvb_get_nstringz0;
408
409         patable.p_tvb_find_line_end             = tvb_find_line_end;
410         patable.p_tvb_find_line_end_unquoted    = tvb_find_line_end_unquoted;
411
412         patable.p_tvb_strneql                   = tvb_strneql;
413         patable.p_tvb_strncaseeql               = tvb_strncaseeql;
414
415         patable.p_tvb_bytes_to_str              = tvb_bytes_to_str;
416
417         patable.p_prefs_register_protocol       = prefs_register_protocol;
418         patable.p_prefs_register_uint_preference = prefs_register_uint_preference;
419         patable.p_prefs_register_bool_preference = prefs_register_bool_preference;
420         patable.p_prefs_register_enum_preference = prefs_register_enum_preference;
421         patable.p_prefs_register_string_preference = prefs_register_string_preference;
422
423         patable.p_register_giop_user            = register_giop_user;
424         patable.p_is_big_endian                 = is_big_endian;
425         patable.p_get_CDR_encap_info            = get_CDR_encap_info;
426
427         patable.p_get_CDR_any                   = get_CDR_any;
428         patable.p_get_CDR_boolean               = get_CDR_boolean;
429         patable.p_get_CDR_char                  = get_CDR_char;
430         patable.p_get_CDR_double                = get_CDR_double;
431         patable.p_get_CDR_enum                  = get_CDR_enum;
432         patable.p_get_CDR_fixed                 = get_CDR_fixed;
433         patable.p_get_CDR_float                 = get_CDR_float;
434         patable.p_get_CDR_interface             = get_CDR_interface;
435         patable.p_get_CDR_long                  = get_CDR_long;
436         patable.p_get_CDR_object                = get_CDR_object;
437         patable.p_get_CDR_octet                 = get_CDR_octet;
438         patable.p_get_CDR_octet_seq             = get_CDR_octet_seq;
439         patable.p_get_CDR_short                 = get_CDR_short;
440         patable.p_get_CDR_string                = get_CDR_string;
441         patable.p_get_CDR_typeCode              = get_CDR_typeCode;
442         patable.p_get_CDR_ulong                 = get_CDR_ulong;
443         patable.p_get_CDR_ushort                = get_CDR_ushort;
444         patable.p_get_CDR_wchar                 = get_CDR_wchar;
445         patable.p_get_CDR_wstring               = get_CDR_wstring;
446
447         patable.p_is_tpkt                       = is_tpkt;
448         patable.p_dissect_tpkt_encap            = dissect_tpkt_encap;
449
450         patable.p_set_actual_length             = set_actual_length;
451         patable.p_decode_boolean_bitfield       = decode_boolean_bitfield;
452         patable.p_decode_numeric_bitfield       = decode_numeric_bitfield;
453         patable.p_decode_enumerated_bitfield    = decode_enumerated_bitfield;
454         patable.p_register_dissector_table      = register_dissector_table;
455         patable.p_except_throw                  = except_throw;
456         patable.p_dissector_try_port            = dissector_try_port;
457
458         patable.p_conversation_add_proto_data   = conversation_add_proto_data;
459         patable.p_conversation_get_proto_data   = conversation_get_proto_data;
460         patable.p_conversation_delete_proto_data = conversation_delete_proto_data;
461         patable.p_p_add_proto_data              = p_add_proto_data;
462         patable.p_p_get_proto_data              = p_get_proto_data;
463
464         patable.p_ip_to_str                     = ip_to_str;
465         patable.p_ip6_to_str                    = ip6_to_str;
466         patable.p_time_secs_to_str              = time_secs_to_str;
467         patable.p_time_msecs_to_str             = time_msecs_to_str;
468         patable.p_abs_time_to_str               = abs_time_to_str;
469
470         patable.p_proto_get_id_by_filter_name   = proto_get_id_by_filter_name;
471         patable.p_proto_get_protocol_name       = proto_get_protocol_name;
472         patable.p_proto_get_protocol_short_name = proto_get_protocol_short_name;
473         patable.p_proto_get_protocol_filter_name        = proto_get_protocol_filter_name;
474
475         patable.p_prefs_register_obsolete_preference    = prefs_register_obsolete_preference;
476
477         patable.p_add_new_data_source           = add_new_data_source;
478
479         patable.p_fragment_table_init           = fragment_table_init;
480         patable.p_reassembled_table_init        = reassembled_table_init;
481         patable.p_fragment_add                  = fragment_add;
482         patable.p_fragment_add_seq              = fragment_add_seq;
483         patable.p_fragment_add_seq_check        = fragment_add_seq_check;
484         patable.p_fragment_add_seq_next         = fragment_add_seq_next;
485         patable.p_fragment_get                  = fragment_get;
486         patable.p_fragment_set_tot_len          = fragment_set_tot_len;
487         patable.p_fragment_get_tot_len          = fragment_get_tot_len;
488         patable.p_fragment_set_partial_reassembly       = fragment_set_partial_reassembly;
489         patable.p_fragment_delete               = fragment_delete;
490         patable.p_show_fragment_tree            = show_fragment_tree;
491         patable.p_show_fragment_seq_tree        = show_fragment_seq_tree;
492         
493         patable.p_register_tap                  = register_tap;
494         patable.p_tap_queue_packet              = tap_queue_packet;
495
496         patable.p_asn1_open                     = asn1_open;
497         patable.p_asn1_close                    = asn1_close;
498         patable.p_asn1_octet_decode             = asn1_octet_decode;
499         patable.p_asn1_tag_decode               = asn1_tag_decode;
500         patable.p_asn1_id_decode                = asn1_id_decode;
501         patable.p_asn1_length_decode            = asn1_length_decode;
502         patable.p_asn1_header_decode            = asn1_header_decode;
503         patable.p_asn1_eoc                      = asn1_eoc;
504         patable.p_asn1_eoc_decode               = asn1_eoc_decode;
505         patable.p_asn1_null_decode              = asn1_null_decode;
506         patable.p_asn1_bool_decode              = asn1_bool_decode;
507         patable.p_asn1_int32_value_decode       = asn1_int32_value_decode;
508         patable.p_asn1_int32_decode             = asn1_int32_decode;
509         patable.p_asn1_uint32_value_decode      = asn1_uint32_value_decode;
510         patable.p_asn1_uint32_decode            = asn1_uint32_decode;
511         patable.p_asn1_bits_decode              = asn1_bits_decode;
512         patable.p_asn1_string_value_decode      = asn1_string_value_decode;
513         patable.p_asn1_string_decode            = asn1_string_decode;
514         patable.p_asn1_octet_string_decode      = asn1_octet_string_decode;
515         patable.p_asn1_subid_decode             = asn1_subid_decode;
516         patable.p_asn1_oid_value_decode         = asn1_oid_value_decode;
517         patable.p_asn1_oid_decode               = asn1_oid_decode;
518         patable.p_asn1_sequence_decode          = asn1_sequence_decode;
519         patable.p_asn1_err_to_str               = asn1_err_to_str;
520         
521         patable.p_proto_item_set_end            = proto_item_set_end;
522         patable.p_proto_tree_add_none_format    = proto_tree_add_none_format;
523
524         patable.p_except_init                   = except_init;
525         patable.p_except_deinit                 = except_deinit;
526         patable.p_except_rethrow                = except_rethrow;
527         patable.p_except_throwd                 = except_throwd;
528         patable.p_except_throwf                 = except_throwf;
529         patable.p_except_unhandled_catcher      = except_unhandled_catcher;
530         patable.p_except_take_data              = except_take_data;
531         patable.p_except_set_allocator          = except_set_allocator;
532         patable.p_except_alloc                  = except_alloc;
533         patable.p_except_free                   = except_free;
534         patable.p_except_pop                    = except_pop;
535         patable.p_except_setup_try              = except_setup_try;
536 #endif
537
538 #ifdef WIN32
539         /*
540          * On Windows, the data file directory is the installation
541          * directory; the plugins are stored under it.
542          *
543          * Assume we're running the installed version of Ethereal;
544          * on Windows, the data file directory is the directory
545          * in which the Ethereal binary resides.
546          */
547         datafile_dir = get_datafile_dir();
548         install_plugin_dir = g_malloc(strlen(datafile_dir) + strlen("plugins") +
549             strlen(VERSION) + 3);
550         sprintf(install_plugin_dir, "%s\\plugins\\%s", datafile_dir, VERSION);
551
552         /*
553          * Make sure that pathname refers to a directory.
554          */
555         if (test_for_directory(install_plugin_dir) != EISDIR) {
556                 /*
557                  * Either it doesn't refer to a directory or it
558                  * refers to something that doesn't exist.
559                  *
560                  * Assume that means we're running, for example,
561                  * a version of Ethereal we've built in a source
562                  * directory, and fall back on the default
563                  * installation directory, so you can put the plugins
564                  * somewhere so they can be used with this version
565                  * of Ethereal.
566                  *
567                  * XXX - should we, instead, have the Windows build
568                  * procedure create a subdirectory of the "plugins"
569                  * source directory, and copy the plugin DLLs there,
570                  * so that you use the plugins from the build tree?
571                  */
572                 install_plugin_dir =
573                     g_strdup("C:\\Program Files\\Ethereal\\plugins\\" VERSION);
574         }
575
576         /*
577          * Scan that directory.
578          */
579         plugins_scan_dir(install_plugin_dir);
580         g_free(install_plugin_dir);
581 #else
582         /*
583          * Scan the plugin directory.
584          */
585         plugins_scan_dir(plugin_dir);
586 #endif
587         if (!user_plug_dir)
588             user_plug_dir = get_persconffile_path(PLUGINS_DIR_NAME, FALSE);
589         plugins_scan_dir(user_plug_dir);
590     }
591 }
592
593 void
594 register_all_plugin_handoffs(void)
595 {
596   plugin *pt_plug;
597
598   /*
599    * For all new-style plugins, call the register-handoff routine.
600    * This is called from "proto_init()"; it must be called after
601    * "register_all_protocols()" and "init_plugins()" are called,
602    * in case one plugin registers itself either with a built-in
603    * dissector or with another plugin; we must first register all
604    * dissectors, whether built-in or plugin, so their dissector tables
605    * are initialized, and only then register all handoffs.
606    *
607    * We treat those protocols as always being enabled; they should
608    * use the standard mechanism for enabling/disabling protocols, not
609    * the plugin-specific mechanism.
610    */
611   for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
612     (pt_plug->reg_handoff)();
613 }
614 #endif