Have editcap and capinfos loading the wiretap plugins.
authorlego <lego@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 25 May 2007 17:22:32 +0000 (17:22 +0000)
committerlego <lego@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 25 May 2007 17:22:32 +0000 (17:22 +0000)
epan/filesystem.c
   have get_plugin_dir() calling init_plugin_dir() if necessary

epan/epan.c and epan/report_err.c
   move the report_failure family into the new report_err.c file, have epan_init() calling the initializer

epan/plugins.h and epan/proto.c
   do not have init_plugins() calling the proto_reg functions instead do it in init_proto()

gtk/main.c and tshark.c
   init_plugin_dir() has become suprefluous

capinfos.c and editcap.c
   load the wiretap plugins

Makefiles
   do what's needed to build withe the above changes.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@21935 f5534014-38df-0310-8fa8-9805f1628bb7

14 files changed:
Makefile.common
Makefile.nmake
capinfos.c
editcap.c
epan/Makefile.common
epan/epan.c
epan/filesystem.c
epan/plugins.c
epan/plugins.h
epan/proto.c
epan/report_err.c [new file with mode: 0644]
epan/report_err.h
gtk/main.c
tshark.c

index 5090d805388c92cb3638cbbf1dadbf9ea7546c1e..5358531d08e0ded909c27917e8b11d8cb337363d 100644 (file)
@@ -207,7 +207,18 @@ mergecap_SOURCES = \
 # editcap specifics
 editcap_SOURCES = \
        editcap.c       \
-       epan/crypt/crypt-md5.c
+       epan/crypt/crypt-md5.c \
+       epan/plugins.c \
+       epan/report_err.c \
+       epan/privileges.c \
+       epan/filesystem.c
+
+capinfos_SOURCES = \
+       capinfos.c \
+        epan/plugins.c \
+        epan/report_err.c \
+        epan/privileges.c \
+        epan/filesystem.c
 
 # dftest specifics
 dftest_SOURCES =       \
index 74be16308e40b5e06441ed41ff9e2db46c4745b6..4d27e46ad7df38fc00e00bd1b0ebc5279755eeff 100644 (file)
@@ -75,11 +75,11 @@ tshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
 !ENDIF
 
 capinfos_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib \
+       wsock32.lib user32.lib shell32.lib \
        $(GLIB_LIBS)
 
 editcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib \
+       wsock32.lib user32.lib shell32.lib \
        $(GLIB_LIBS)
 
 mergecap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
@@ -214,19 +214,19 @@ tshark.exe        : config.h svnversion.h $(tshark_OBJECTS) getopt.obj epan image\tshar
        mt.exe -nologo -manifest "tshark.exe.manifest" -outputresource:tshark.exe;1
 !ENDIF
 
-capinfos.exe   : config.h capinfos.obj getopt.obj wiretap\wiretap-$(WTAP_VERSION).lib image\capinfos.res
+capinfos.exe   : config.h capinfos.obj getopt.obj epan/unicode-utils.obj epan/plugins.obj epan/report_err.obj epan/privileges.obj epan/filesystem.obj wiretap\wiretap-$(WTAP_VERSION).lib image\capinfos.res
        @echo Linking $@
        $(LINK) @<<
-               /OUT:capinfos.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console capinfos.obj getopt.obj $(capinfos_LIBS) image\capinfos.res
+               /OUT:capinfos.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console capinfos.obj getopt.obj epan/unicode-utils.obj epan/plugins.obj epan/report_err.obj epan/privileges.obj epan/filesystem.obj $(capinfos_LIBS) image\capinfos.res
 <<
 !IF "$(MSVC_VARIANT)" == "MSVC2005" || "$(MSVC_VARIANT)" == "MSVC2005EE" || "$(MSVC_VARIANT)" == "DOTNET20" 
        mt.exe -nologo -manifest "capinfos.exe.manifest" -outputresource:capinfos.exe;1
 !ENDIF
 
-editcap.exe    : config.h editcap.obj getopt.obj strptime.obj epan\crypt\crypt-md5.obj wiretap\wiretap-$(WTAP_VERSION).lib image\editcap.res
+editcap.exe    : config.h editcap.obj getopt.obj strptime.obj epan\crypt\crypt-md5.obj epan/unicode-utils.obj epan/plugins.obj epan/report_err.obj epan/privileges.obj epan/filesystem.obj wiretap\wiretap-$(WTAP_VERSION).lib image\editcap.res
        @echo Linking $@
        $(LINK) @<<
-               /OUT:editcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console editcap.obj getopt.obj strptime.obj epan\crypt\crypt-md5.obj $(editcap_LIBS) image\editcap.res
+               /OUT:editcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console editcap.obj getopt.obj strptime.obj epan/unicode-utils.obj epan\crypt\crypt-md5.obj epan/plugins.obj epan/report_err.obj epan/privileges.obj epan/filesystem.obj $(editcap_LIBS) image\editcap.res
 <<
 !IF "$(MSVC_VARIANT)" == "MSVC2005" || "$(MSVC_VARIANT)" == "MSVC2005EE" || "$(MSVC_VARIANT)" == "DOTNET20" 
        mt.exe -nologo -manifest "editcap.exe.manifest" -outputresource:editcap.exe;1
@@ -870,6 +870,8 @@ install-common-files:
        xcopy ".\cfilters" $(INSTALL_DIR) /d
        xcopy ".\colorfilters" $(INSTALL_DIR) /d
        xcopy ".\dfilters" $(INSTALL_DIR) /d
+       xcopy ".\epan\wslua\init.lua" $(INSTALL_DIR) /d
+       xcopy ".\epan\wslua\console.lua" $(INSTALL_DIR) /d
     xcopy doc\*.html $(INSTALL_DIR) /d
 !IFDEF ETHEREAL_EUG_DIR
     xcopy $(ETHEREAL_EUG_DIR) $(INSTALL_DIR) /d
@@ -1026,3 +1028,4 @@ clean-deps2:
 
 clean-deps: clean-deps1 clean-deps2
 
+
index 1b6ff6a6bb9b98fd9db674bf0e391951852c39c4..bda6ea6faa380a7183fffce21dcc6dab9a0e7774 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdarg.h>
 #include <errno.h>
 
 #ifdef HAVE_UNISTD_H
@@ -44,6 +45,9 @@
 #include <glib.h>
 
 #include <epan/packet.h>
+#include <epan/filesystem.h>
+#include <epan/plugins.h>
+#include <epan/report_err.h>
 #include "wtap.h"
 
 #ifdef NEED_GETOPT_H
@@ -247,6 +251,18 @@ static void usage(gboolean is_error)
   fprintf(output, "If no options are given, default is to display all infos\n");
 }
 
+/*
+ * Errors are reported with a console message.
+ */
+static void
+failure_message(const char *msg_format, va_list ap)
+{
+       fprintf(stderr, "capinos: ");
+       vfprintf(stderr, msg_format, ap);
+       fprintf(stderr, "\n");
+}
+
+
 int main(int argc, char *argv[])
 {
   wtap *wth;
@@ -256,8 +272,20 @@ int main(int argc, char *argv[])
   extern int optind;
   int opt;
   int status = 0;
-
-  /* Process the options first */
+  char* init_progfile_dir_error;
+       
+  /* Register wiretap plugins */
+
+    if ((init_progfile_dir_error = init_progfile_dir(argv[0]))) {
+       g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
+       g_free(init_progfile_dir_error);
+    } else {
+       init_report_err(failure_message,NULL,NULL);
+       init_plugins();
+       register_all_wiretap_modules();
+    }
+    
+  /* Process the options */
 
   while ((opt = getopt(argc, argv, "tcsduaeyizvh")) !=-1) {
 
index 2a11bf7a109ca41b1bb0b441c4a6a8baaf0899c0..4a033d351a9725f6e6dc45a6cdf342372529cf01 100644 (file)
--- a/editcap.c
+++ b/editcap.c
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdarg.h>
 
 /*
  * Just make sure we include the prototype for strptime as well
@@ -54,6 +55,9 @@
 #endif
 
 #include "epan/crypt/crypt-md5.h"
+#include "epan/plugins.h"
+#include "epan/report_err.h"
+#include "epan/filesystem.h"
 
 #include "svnversion.h"
 
@@ -346,6 +350,14 @@ static void list_encap_types(void) {
     }
 }
 
+static void
+failure_message(const char *msg_format, va_list ap)
+{
+       fprintf(stderr, "editcap: ");
+       vfprintf(stderr, msg_format, ap);
+       fprintf(stderr, "\n");
+}
+
 int main(int argc, char *argv[])
 
 {
@@ -368,9 +380,19 @@ int main(int argc, char *argv[])
   int split_packet_count = 0;
   int written_count = 0;
   char *filename;
-
-  /* Process the options first */
-
+  char* init_progfile_dir_error;
+  
+  /* Register wiretap plugins */
+    if ((init_progfile_dir_error = init_progfile_dir(argv[0]))) {
+       g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
+       g_free(init_progfile_dir_error);
+    } else {
+       init_report_err(failure_message,NULL,NULL);
+       init_plugins();
+       register_all_wiretap_modules();
+    }
+    
+  /* Process the options */
   while ((opt = getopt(argc, argv, "A:B:c:C:dE:F:hrs:t:T:v")) !=-1) {
 
     switch (opt) {
index 9d226bbd4a22c1e98ae6ae0fa6c19f608e7b7fd4..1cd132dd4a3279497b7ea3d7e51617ef2305b210 100644 (file)
@@ -68,6 +68,7 @@ LIBWIRESHARK_SRC =            \
        range.c                 \
        reassemble.c            \
        reedsolomon.c           \
+       report_err.c            \
        req_resp_hdrs.c         \
        sigcomp_state_hdlr.c    \
        sigcomp-udvm.c          \
index 765859036b2ff62ed3fe2039e47cab11879a3663..e6c8b5d41474b1051d42a5e50d82a84b3fa7c57a 100644 (file)
        int wslua_init(void*);
 #endif
 
-static void (*report_failure_func)(const char *, va_list);
-static void (*report_open_failure_func)(const char *, int, gboolean);
-static void (*report_read_failure_func)(const char *, int);
-
 gchar*
 epan_get_version(void) {
   return VERSION;
@@ -76,9 +72,7 @@ epan_init(void (*register_all_protocols)(register_cb cb, gpointer client_data),
          void (*report_open_failure)(const char *, int, gboolean),
          void (*report_read_failure)(const char *, int))
 {
-       report_failure_func = report_failure;
-       report_open_failure_func = report_open_failure;
-       report_read_failure_func = report_read_failure;
+       init_report_err(report_failure, report_open_failure, report_read_failure);
 
        /* initialize memory allocation subsystem */
        ep_init_chunk();
@@ -136,42 +130,6 @@ epan_circuit_init(void)
        circuit_init();
 }
 
-/*
- * Report a general error.
- */
-void
-report_failure(const char *msg_format, ...)
-{
-       va_list ap;
-
-       va_start(ap, msg_format);
-       (*report_failure_func)(msg_format, ap);
-       va_end(ap);
-}
-
-/*
- * Report an error when trying to open or create a file.
- * "err" is assumed to be an error code from Wiretap; positive values are
- * UNIX-style errnos, so this can be used for open failures not from
- * Wiretap as long as the failue code is just an errno.
- */
-void
-report_open_failure(const char *filename, int err,
-    gboolean for_writing)
-{
-       (*report_open_failure_func)(filename, err, for_writing);
-}
-
-/*
- * Report an error when trying to read a file.
- * "err" is assumed to be a UNIX-style errno.
- */
-void
-report_read_failure(const char *filename, int err)
-{
-       (*report_read_failure_func)(filename, err);
-}
-
 epan_dissect_t*
 epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
 {
index f0ce0826537f4acde2f3aef53cbfad04c6f2ceed..cd9bb0396b8bb7f9a4f33c083cbeb4f89fdcd945 100644 (file)
@@ -636,7 +636,7 @@ get_datafile_dir(void)
  * of the plugin directory, so it can just fetch the plugins built
  * as part of the build process.
  */
-static const char *plugin_dir;
+static const char *plugin_dir = NULL;
 
 void
 init_plugin_dir(void)
@@ -694,6 +694,7 @@ init_plugin_dir(void)
 const char *
 get_plugin_dir(void)
 {
+       if (!plugin_dir) init_plugin_dir();
        return plugin_dir;
 }
 
index 4841751311990fe6b45532af44974374269bdc6b..8425945ad91d133552c4bc24fec49e072f3be95a 100644 (file)
@@ -173,6 +173,7 @@ plugins_scan_dir(const char *dirname)
 
     if ((dir = eth_dir_open(dirname, 0, NULL)) != NULL)
     {
+
     while ((file = eth_dir_read_name(dir)) != NULL)
        {
            name = eth_dir_get_name(file);
@@ -344,14 +345,6 @@ plugins_scan_dir(const char *dirname)
                continue;
            }
                
-           /*
-            * Call its register routine if it has one.
-            * XXX - just save this and call it with the built-in
-            * dissector register routines?
-            */
-           if (register_protoinfo != NULL)
-                   register_protoinfo();
-
        }
        eth_dir_close(dir);
        }
@@ -440,6 +433,27 @@ init_plugins(void)
     }
 }
 
+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)();
+    }
+}
+
 void
 register_all_plugin_handoffs(void)
 {
index b554a6013f07a30b1f54b71e3a4e9eb2683efa9a..c6a43ab2c91aaf52fe11bf513e4d88011599b10a 100644 (file)
@@ -44,6 +44,7 @@ typedef struct _plugin {
 WS_VAR_IMPORT plugin *plugin_list;
 
 extern void init_plugins(void);
+extern void register_all_plugin_registrations(void);
 extern void register_all_plugin_handoffs(void);
 extern void register_all_plugin_tap_listeners(void);
 extern void register_all_wiretap_modules(void);
index c156b1226397468f24622b5307236b0d7a8dab86..5c5ee49fd39103367dbd640fba059127dd0cd5bf 100644 (file)
@@ -354,6 +354,7 @@ proto_init(void (register_all_protocols)(register_cb cb, gpointer client_data),
        if(cb) 
          (*cb)(RA_PLUGIN_REGISTER, NULL, client_data);
        init_plugins();
+       register_all_plugin_registrations();
 #endif
 
        /* Now call the "handoff registration" routines of all built-in
diff --git a/epan/report_err.c b/epan/report_err.c
new file mode 100644 (file)
index 0000000..bab1aa6
--- /dev/null
@@ -0,0 +1,80 @@
+/* report_err.h
+* Declarations of routines for dissectors to use to report errors to
+* the user (e.g., problems with preference settings)
+*
+* $Id$
+*
+* Wireshark - Network traffic analyzer
+* By Gerald Combs <gerald@wireshark.org>
+* Copyright 1998 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.
+*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib.h>
+#include <stdarg.h>
+#include "report_err.h"
+
+static void (*report_failure_func)(const char *, va_list);
+static void (*report_open_failure_func)(const char *, int, gboolean);
+static void (*report_read_failure_func)(const char *, int);
+
+void init_report_err(void (*report_failure)(const char *, va_list),
+                                        void (*report_open_failure)(const char *, int, gboolean),
+                                        void (*report_read_failure)(const char *, int)) {
+       report_failure_func = report_failure;
+       report_open_failure_func = report_open_failure;
+       report_read_failure_func = report_read_failure;
+}
+
+/*
+ * Report a general error.
+ */
+void
+report_failure(const char *msg_format, ...)
+{
+       va_list ap;
+       
+       va_start(ap, msg_format);
+       (*report_failure_func)(msg_format, ap);
+       va_end(ap);
+}
+
+/*
+ * Report an error when trying to open or create a file.
+ * "err" is assumed to be an error code from Wiretap; positive values are
+ * UNIX-style errnos, so this can be used for open failures not from
+ * Wiretap as long as the failue code is just an errno.
+ */
+void
+report_open_failure(const char *filename, int err,
+                                       gboolean for_writing)
+{
+       (*report_open_failure_func)(filename, err, for_writing);
+}
+
+/*
+ * Report an error when trying to read a file.
+ * "err" is assumed to be a UNIX-style errno.
+ */
+void
+report_read_failure(const char *filename, int err)
+{
+       (*report_read_failure_func)(filename, err);
+}
+
index c9686413c87c0bb7928dc4dc6049e074ce05ec6c..159cd96ceeb214271cfdeea406572252b8a25cfe 100644 (file)
 extern "C" {
 #endif /* __cplusplus */
 
+/*
+ *  Initialize the report err routines
+ */
+extern void init_report_err(
+       void (*report_failure)(const char *, va_list),
+       void (*report_open_failure)(const char *, int, gboolean),
+       void (*report_read_failure)(const char *, int));
+
 /*
  * Report an error when trying to open a file.
  */
index a2adf38e743ae527cba3ef0f5bee4e89e7926713..a6f33d04c3b1af74b17de142e004c7b739a96b51 100644 (file)
@@ -2159,11 +2159,6 @@ main(int argc, char *argv[])
    */
   init_progfile_dir_error = init_progfile_dir(argv[0]);
 
-  /*
-   * Now attempt to get the pathname of the plugins.
-   */
-  init_plugin_dir();
-  
   /* initialize the funnel mini-api */
   initialize_funnel_ops();
 
index 6d9d48ad2cf4c52e533b3a3358c8df6a34d3baef..b30ce80bd50c566a0b0fc4d4b8253418471a2bd5 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -734,11 +734,6 @@ main(int argc, char *argv[])
             init_progfile_dir_error);
   }
 
-  /*
-   * Now attempt to get the pathname of the plugins.
-   */
-  init_plugin_dir();
-
   /*
    * In order to have the -X opts assigned before the wslua machine starts
    * we need to call getopts before epan_init() gets called.