summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2014-09-25 16:21:02 -0700
committerGerald Combs <gerald@wireshark.org>2014-09-26 14:15:45 +0000
commit2d7c1135ed7bb93b6eb2fd0170443d3c990f1e1e (patch)
treec96b56b6aaf00a85609747af3a6bc887352fcb36 /ui
parentce36b20ca5d01490acd1fb6ca44a82dab85ba2a2 (diff)
downloadwireshark-2d7c1135ed7bb93b6eb2fd0170443d3c990f1e1e.tar.gz
Move the console log handling code to ui/console.[ch].
Change-Id: I8e554a8e17399d78b0ef29dfb68109a219cd9f1b Reviewed-on: https://code.wireshark.org/review/4294 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui')
-rw-r--r--ui/CMakeLists.txt1
-rw-r--r--ui/Makefile.common2
-rw-r--r--ui/console.c174
-rw-r--r--ui/console.h57
-rw-r--r--ui/gtk/main.c133
-rw-r--r--ui/qt/main.cpp88
-rw-r--r--ui/util.c6
7 files changed, 241 insertions, 220 deletions
diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt
index 1c209848fa..f964c3a3cc 100644
--- a/ui/CMakeLists.txt
+++ b/ui/CMakeLists.txt
@@ -24,6 +24,7 @@ set(COMMON_UI_SRC
alert_box.c
capture.c
capture_ui_utils.c
+ console.c
decode_as_utils.c
export_object.c
export_object_dicom.c
diff --git a/ui/Makefile.common b/ui/Makefile.common
index bcfb54e9f1..9da5fb17ba 100644
--- a/ui/Makefile.common
+++ b/ui/Makefile.common
@@ -45,6 +45,7 @@ WIRESHARK_UI_SRC = \
alert_box.c \
capture.c \
capture_ui_utils.c \
+ console.c \
decode_as_utils.c \
export_object.c \
export_object_dicom.c \
@@ -80,6 +81,7 @@ noinst_HEADERS = \
capture.h \
capture_globals.h \
capture_ui_utils.h \
+ console.h \
decode_as_utils.h \
export_object.h \
last_open_dir.h \
diff --git a/ui/console.c b/ui/console.c
new file mode 100644
index 0000000000..6ca783030d
--- /dev/null
+++ b/ui/console.c
@@ -0,0 +1,174 @@
+/* console.c
+ * Console log handler routines
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include <glib.h>
+
+#include "epan/prefs.h"
+
+#include "console.h"
+
+#include "log.h"
+
+static void
+console_log_handler(const char *log_domain, GLogLevelFlags log_level,
+ const char *message, gpointer user_data _U_)
+{
+ time_t curr;
+ struct tm *today;
+ const char *level;
+
+
+ /* ignore log message, if log_level isn't interesting based
+ upon the console log preferences.
+ If the preferences haven't been loaded loaded yet, display the
+ message anyway.
+
+ The default console_log_level preference value is such that only
+ ERROR, CRITICAL and WARNING level messages are processed;
+ MESSAGE, INFO and DEBUG level messages are ignored. */
+ if((log_level & G_LOG_LEVEL_MASK & prefs.console_log_level) == 0 &&
+ prefs.console_log_level != 0) {
+ return;
+ }
+
+#ifdef _WIN32
+ if (prefs.gui_console_open != console_open_never || log_level & G_LOG_LEVEL_ERROR) {
+ /* the user wants a console or the application will terminate immediately */
+ create_console();
+ }
+ if (get_has_console()) {
+ /* For some unknown reason, the above doesn't appear to actually cause
+ anything to be sent to the standard output, so we'll just splat the
+ message out directly, just to make sure it gets out. */
+#endif
+ switch(log_level & G_LOG_LEVEL_MASK) {
+ case G_LOG_LEVEL_ERROR:
+ level = "Err ";
+ break;
+ case G_LOG_LEVEL_CRITICAL:
+ level = "Crit";
+ break;
+ case G_LOG_LEVEL_WARNING:
+ level = "Warn";
+ break;
+ case G_LOG_LEVEL_MESSAGE:
+ level = "Msg ";
+ break;
+ case G_LOG_LEVEL_INFO:
+ level = "Info";
+ break;
+ case G_LOG_LEVEL_DEBUG:
+ level = "Dbg ";
+ break;
+ default:
+ fprintf(stderr, "unknown log_level %u\n", log_level);
+ level = NULL;
+ g_assert_not_reached();
+ }
+
+ /* create a "timestamp" */
+ time(&curr);
+ today = localtime(&curr);
+
+ fprintf(stderr, "%02u:%02u:%02u %8s %s %s\n",
+ today->tm_hour, today->tm_min, today->tm_sec,
+ log_domain != NULL ? log_domain : "",
+ level, message);
+#ifdef _WIN32
+ if(log_level & G_LOG_LEVEL_ERROR) {
+ /* wait for a key press before the following error handler will terminate the program
+ this way the user at least can read the error message */
+ printf("\n\nPress any key to exit\n");
+ _getch();
+ }
+ } else {
+ /* XXX - on UN*X, should we just use g_log_default_handler()?
+ We want the error messages to go to the standard output;
+ on Mac OS X, that will cause them to show up in various
+ per-user logs accessible through Console (details depend
+ on whether you're running 10.0 through 10.4 or running
+ 10.5 and later), and, on other UN*X desktop environments,
+ if they don't show up in some form of console log, that's
+ a deficiency in that desktop environment. (Too bad
+ Windows doesn't set the standard output and error for
+ GUI apps to something that shows up in such a log.) */
+ g_log_default_handler(log_domain, log_level, message, user_data);
+ }
+#endif
+}
+
+void set_console_log_handler(void)
+{
+ GLogLevelFlags log_flags;
+ /* Arrange that if we have no console window, and a GLib message logging
+ routine is called to log a message, we pop up a console window.
+
+ We do that by inserting our own handler for all messages logged
+ to the default domain; that handler pops up a console if necessary,
+ and then calls the default handler. */
+
+ /* We might want to have component specific log levels later ... */
+
+ log_flags = (GLogLevelFlags)
+ (G_LOG_LEVEL_ERROR|
+ G_LOG_LEVEL_CRITICAL|
+ G_LOG_LEVEL_WARNING|
+ G_LOG_LEVEL_MESSAGE|
+ G_LOG_LEVEL_INFO|
+ G_LOG_LEVEL_DEBUG|
+ G_LOG_FLAG_FATAL|
+ G_LOG_FLAG_RECURSION);
+
+ g_log_set_handler(NULL,
+ log_flags,
+ console_log_handler, NULL /* user_data */);
+ g_log_set_handler(LOG_DOMAIN_MAIN,
+ log_flags,
+ console_log_handler, NULL /* user_data */);
+
+#ifdef HAVE_LIBPCAP
+ g_log_set_handler(LOG_DOMAIN_CAPTURE,
+ log_flags,
+ console_log_handler, NULL /* user_data */);
+ g_log_set_handler(LOG_DOMAIN_CAPTURE_CHILD,
+ log_flags,
+ console_log_handler, NULL /* user_data */);
+
+#endif
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/console.h b/ui/console.h
new file mode 100644
index 0000000000..53343d1ab1
--- /dev/null
+++ b/ui/console.h
@@ -0,0 +1,57 @@
+/* console.h
+ * Console log handler routines
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __CONSOLE_H__
+#define __CONSOLE_H__
+
+#ifdef _WIN32 /* Needed for console I/O */
+#include <fcntl.h>
+#include <conio.h>
+#include <ui/win32/console_win32.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/** Set the console log handler.
+ */
+void set_console_log_handler(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __CONSOLE_H__ */
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index 510b85fc92..34ddb0b0f8 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -49,13 +49,6 @@
#include <zlib.h> /* to get the libz version number */
#endif
-#ifdef _WIN32 /* Needed for console I/O */
-
-#include <fcntl.h>
-#include <conio.h>
-#include <ui/win32/console_win32.h>
-#endif
-
#ifdef HAVE_LIBPORTAUDIO
#include <portaudio.h>
#endif /* HAVE_LIBPORTAUDIO */
@@ -111,6 +104,7 @@
#include "gtk_iface_monitor.h"
#include "ui/alert_box.h"
+#include "ui/console.h"
#include "ui/decode_as_utils.h"
#include "ui/filters.h"
#include "ui/main_statusbar.h"
@@ -250,9 +244,6 @@ static gboolean have_capture_file = FALSE; /* XXX - is there an equivalent in cf
static guint tap_update_timer_id;
-static void console_log_handler(const char *log_domain,
- GLogLevelFlags log_level, const char *message, gpointer user_data);
-
static void create_main_window(gint, gint, gint, e_prefs*);
static void show_main_window(gboolean);
static void main_save_window_geometry(GtkWidget *widget);
@@ -2180,7 +2171,6 @@ main(int argc, char *argv[])
e_prefs *prefs_p;
char badopt;
GtkWidget *splash_win = NULL;
- GLogLevelFlags log_flags;
guint go_to_packet = 0;
search_direction jump_backwards = SD_FORWARD;
dfilter_t *jump_to_filter = NULL;
@@ -2472,40 +2462,9 @@ main(int argc, char *argv[])
capture_callback_add(statusbar_capture_callback, NULL);
#endif
- /* Arrange that if we have no console window, and a GLib message logging
- routine is called to log a message, we pop up a console window.
-
- We do that by inserting our own handler for all messages logged
- to the default domain; that handler pops up a console if necessary,
- and then calls the default handler. */
-
- /* We might want to have component specific log levels later ... */
-
- log_flags = (GLogLevelFlags)
- (G_LOG_LEVEL_ERROR|
- G_LOG_LEVEL_CRITICAL|
- G_LOG_LEVEL_WARNING|
- G_LOG_LEVEL_MESSAGE|
- G_LOG_LEVEL_INFO|
- G_LOG_LEVEL_DEBUG|
- G_LOG_FLAG_FATAL|
- G_LOG_FLAG_RECURSION);
-
- g_log_set_handler(NULL,
- log_flags,
- console_log_handler, NULL /* user_data */);
- g_log_set_handler(LOG_DOMAIN_MAIN,
- log_flags,
- console_log_handler, NULL /* user_data */);
+ set_console_log_handler();
#ifdef HAVE_LIBPCAP
- g_log_set_handler(LOG_DOMAIN_CAPTURE,
- log_flags,
- console_log_handler, NULL /* user_data */);
- g_log_set_handler(LOG_DOMAIN_CAPTURE_CHILD,
- log_flags,
- console_log_handler, NULL /* user_data */);
-
/* Set the initial values in the capture options. This might be overwritten
by preference settings and then again by the command line parameters. */
capture_opts_init(&global_capture_opts);
@@ -3341,93 +3300,6 @@ WinMain (struct HINSTANCE__ *hInstance,
#endif /* _WIN32 */
-static void
-console_log_handler(const char *log_domain, GLogLevelFlags log_level,
- const char *message, gpointer user_data _U_)
-{
- time_t curr;
- struct tm *today;
- const char *level;
-
-
- /* ignore log message, if log_level isn't interesting based
- upon the console log preferences.
- If the preferences haven't been loaded loaded yet, display the
- message anyway.
-
- The default console_log_level preference value is such that only
- ERROR, CRITICAL and WARNING level messages are processed;
- MESSAGE, INFO and DEBUG level messages are ignored. */
- if((log_level & G_LOG_LEVEL_MASK & prefs.console_log_level) == 0 &&
- prefs.console_log_level != 0) {
- return;
- }
-
-#ifdef _WIN32
- if (prefs.gui_console_open != console_open_never || log_level & G_LOG_LEVEL_ERROR) {
- /* the user wants a console or the application will terminate immediately */
- create_console();
- }
- if (get_has_console()) {
- /* For some unknown reason, the above doesn't appear to actually cause
- anything to be sent to the standard output, so we'll just splat the
- message out directly, just to make sure it gets out. */
-#endif
- switch(log_level & G_LOG_LEVEL_MASK) {
- case G_LOG_LEVEL_ERROR:
- level = "Err ";
- break;
- case G_LOG_LEVEL_CRITICAL:
- level = "Crit";
- break;
- case G_LOG_LEVEL_WARNING:
- level = "Warn";
- break;
- case G_LOG_LEVEL_MESSAGE:
- level = "Msg ";
- break;
- case G_LOG_LEVEL_INFO:
- level = "Info";
- break;
- case G_LOG_LEVEL_DEBUG:
- level = "Dbg ";
- break;
- default:
- fprintf(stderr, "unknown log_level %u\n", log_level);
- level = NULL;
- g_assert_not_reached();
- }
-
- /* create a "timestamp" */
- time(&curr);
- today = localtime(&curr);
-
- fprintf(stderr, "%02u:%02u:%02u %8s %s %s\n",
- today->tm_hour, today->tm_min, today->tm_sec,
- log_domain != NULL ? log_domain : "",
- level, message);
-#ifdef _WIN32
- if(log_level & G_LOG_LEVEL_ERROR) {
- /* wait for a key press before the following error handler will terminate the program
- this way the user at least can read the error message */
- printf("\n\nPress any key to exit\n");
- _getch();
- }
- } else {
- /* XXX - on UN*X, should we just use g_log_default_handler()?
- We want the error messages to go to the standard output;
- on Mac OS X, that will cause them to show up in various
- per-user logs accessible through Console (details depend
- on whether you're running 10.0 through 10.4 or running
- 10.5 and later), and, on other UN*X desktop environments,
- if they don't show up in some form of console log, that's
- a deficiency in that desktop environment. (Too bad
- Windows doesn't set the standard output and error for
- GUI apps to something that shows up in such a log.) */
- g_log_default_handler(log_domain, log_level, message, user_data);
- }
-#endif
-}
/*
@@ -3454,7 +3326,6 @@ static GtkWidget *main_widget_layout(gint layout_content)
}
}
-
/*
* Rearrange the main window widgets
*/
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp
index 82dc1d09fd..efbadac64f 100644
--- a/ui/qt/main.cpp
+++ b/ui/qt/main.cpp
@@ -100,6 +100,7 @@
#ifdef HAVE_LIBPCAP
# include "ui/capture_ui_utils.h"
#endif
+#include "ui/console.h"
#include "ui/iface_lists.h"
#include "ui/main_statusbar.h"
#include "ui/persfilepath_opt.h"
@@ -122,8 +123,6 @@
# include <wsutil/unicode-utils.h>
# include <commctrl.h>
# include <shellapi.h>
-# include <conio.h>
-# include "ui/win32/console_win32.h"
#endif /* _WIN32 */
#ifdef HAVE_AIRPCAP
@@ -161,10 +160,6 @@ GString *comp_info_str, *runtime_info_str;
//static gboolean have_capture_file = FALSE; /* XXX - is there an equivalent in cfile? */
-static void console_log_handler(const char *log_domain,
- GLogLevelFlags log_level, const char *message, gpointer user_data);
-
-
#ifdef HAVE_LIBPCAP
extern capture_options global_capture_opts;
@@ -357,54 +352,6 @@ wireshark_cmdarg_err_cont(const char *fmt, va_list ap)
fprintf(stderr, "\n");
}
-static void
-console_log_handler(const char *log_domain, GLogLevelFlags log_level,
- const char *message, gpointer user_data)
-{
- Q_UNUSED(user_data);
- QString level;
- QString hmsz = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
-
-// xxx qtshark: We want all of the messages for now.
-// /* ignore log message, if log_level isn't interesting based
-// upon the console log preferences.
-// If the preferences haven't been loaded loaded yet, display the
-// message anyway.
-
-// The default console_log_level preference value is such that only
-// ERROR, CRITICAL and WARNING level messages are processed;
-// MESSAGE, INFO and DEBUG level messages are ignored. */
-// if((log_level & G_LOG_LEVEL_MASK & prefs.console_log_level) == 0 &&
-// prefs.console_log_level != 0) {
-// return;
-
- switch(log_level & G_LOG_LEVEL_MASK) {
- case G_LOG_LEVEL_ERROR:
- level = "Err ";
- break;
- case G_LOG_LEVEL_CRITICAL:
- level = "Crit";
- break;
- case G_LOG_LEVEL_WARNING:
- level = "Warn";
- break;
- case G_LOG_LEVEL_MESSAGE:
- level = "Msg ";
- break;
- case G_LOG_LEVEL_INFO:
- level = "Info";
- break;
- case G_LOG_LEVEL_DEBUG:
- level = "Dbg ";
- break;
- default:
- qDebug("%s unknown log_level %u", hmsz.toUtf8().constData(), log_level);
- g_assert_not_reached();
- }
-
- qDebug("%s %s %s %s", hmsz.toUtf8().constData(), log_domain, level.toUtf8().constData(), message);
- }
-
// xxx based from ../gtk/main.c:get_gtk_compiled_info
static void
get_wireshark_qt_compiled_info(GString *str)
@@ -514,7 +461,6 @@ int main(int argc, char *argv[])
#endif
e_prefs *prefs_p;
char badopt;
- GLogLevelFlags log_flags;
cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont);
@@ -838,39 +784,9 @@ int main(int argc, char *argv[])
#endif
cf_callback_add(main_cf_callback, NULL);
- /* Arrange that if we have no console window, and a GLib message logging
- routine is called to log a message, we pop up a console window.
-
- We do that by inserting our own handler for all messages logged
- to the default domain; that handler pops up a console if necessary,
- and then calls the default handler. */
-
- /* We might want to have component specific log levels later ... */
-
- log_flags = (GLogLevelFlags) (
- G_LOG_LEVEL_ERROR|
- G_LOG_LEVEL_CRITICAL|
- G_LOG_LEVEL_WARNING|
- G_LOG_LEVEL_MESSAGE|
- G_LOG_LEVEL_INFO|
- G_LOG_LEVEL_DEBUG|
- G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION );
-
- g_log_set_handler(NULL,
- log_flags,
- console_log_handler, NULL /* user_data */);
- g_log_set_handler(LOG_DOMAIN_MAIN,
- log_flags,
- console_log_handler, NULL /* user_data */);
+ set_console_log_handler();
#ifdef HAVE_LIBPCAP
- g_log_set_handler(LOG_DOMAIN_CAPTURE,
- log_flags,
- console_log_handler, NULL /* user_data */);
- g_log_set_handler(LOG_DOMAIN_CAPTURE_CHILD,
- log_flags,
- console_log_handler, NULL /* user_data */);
-
/* Set the initial values in the capture options. This might be overwritten
by preference settings and then again by the command line parameters. */
capture_opts_init(&global_capture_opts);
diff --git a/ui/util.c b/ui/util.c
index fabaa8c1a1..9f7ba6e65b 100644
--- a/ui/util.c
+++ b/ui/util.c
@@ -37,9 +37,9 @@
#include <windows.h>
#endif
-#include <epan/address.h>
-#include <epan/addr_resolv.h>
-#include <epan/strutil.h>
+#include "epan/address.h"
+#include "epan/addr_resolv.h"
+#include "epan/strutil.h"
#include "ui/util.h"