fix various doxygen warnings
[obnox/wireshark/wip.git] / gtk / nameres_prefs.c
1 /* nameres_prefs.c
2  * Dialog box for name resolution preferences
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 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 #include <gtk/gtk.h>
30
31 #include "globals.h"
32 #include "nameres_prefs.h"
33 #include "gtkglobals.h"
34 #include <epan/addr_resolv.h>
35 #include <epan/prefs.h>
36 #include "prefs_dlg.h"
37 #include "ui_util.h"
38 #include "main.h"
39 #include "menu.h"
40 #include "compat_macros.h"
41
42 #define M_RESOLVE_KEY   "m_resolve"
43 #define N_RESOLVE_KEY   "n_resolve"
44 #define T_RESOLVE_KEY   "t_resolve"
45 #ifdef HAVE_GNU_ADNS
46 # define C_RESOLVE_KEY  "c_resolve"
47 # define RESOLVE_CONCURRENCY_KEY "resolve_concurrency"
48 #endif /* HAVE_GNU_ADNS */
49
50 #ifdef HAVE_GNU_ADNS
51 # define RESOLV_TABLE_ROWS 5
52 #else
53 # define RESOLV_TABLE_ROWS 3
54 #endif /* HAVE_GNU_ADNS */
55 GtkWidget*
56 nameres_prefs_show(void)
57 {
58         GtkWidget       *main_tb, *main_vb;
59         GtkWidget       *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
60         GtkTooltips *tooltips = gtk_tooltips_new();
61 #ifdef HAVE_GNU_ADNS
62         GtkWidget       *c_resolv_cb, *resolv_concurrency_te;
63         char            concur_str[10+1];
64 #endif /* HAVE_GNU_ADNS */
65
66         /*
67          * XXX - it would be nice if the current setting of the resolver
68          * flags could be different from the preference flags, so that
69          * the preference flags would represent what the user *typically*
70          * wants, but they could override them for particular captures
71          * without a subsequent editing of the preferences recording the
72          * temporary settings as permanent preferences.
73          */
74         prefs.name_resolve = g_resolv_flags;
75
76         /* Main vertical box */
77         main_vb = gtk_vbox_new(FALSE, 7);
78         gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
79
80         /* Main table */
81         main_tb = gtk_table_new(RESOLV_TABLE_ROWS, 3, FALSE);
82         gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
83         gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
84         gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
85         gtk_widget_show(main_tb);
86     OBJECT_SET_DATA(main_tb, E_TOOLTIPS_KEY, tooltips);
87
88         /* Resolve MAC addresses */
89         m_resolv_cb = create_preference_check_button(main_tb, 0,
90             "Enable MAC name resolution:", "e.g. Ethernet address to manufacturer name",
91             prefs.name_resolve & RESOLV_MAC);
92         OBJECT_SET_DATA(main_vb, M_RESOLVE_KEY, m_resolv_cb);
93
94         /* Resolve network addresses */
95         n_resolv_cb = create_preference_check_button(main_tb, 1,
96             "Enable network name resolution:", "e.g. IP address to DNS name (hostname)",
97             prefs.name_resolve & RESOLV_NETWORK);
98         OBJECT_SET_DATA(main_vb, N_RESOLVE_KEY, n_resolv_cb);
99
100         /* Resolve transport addresses */
101         t_resolv_cb = create_preference_check_button(main_tb, 2,
102             "Enable transport name resolution:", "e.g. TCP/UDP port to service name",
103             prefs.name_resolve & RESOLV_TRANSPORT);
104         OBJECT_SET_DATA(main_vb, T_RESOLVE_KEY, t_resolv_cb);
105
106 #ifdef HAVE_GNU_ADNS
107         /* Enable concurrent (asynchronous) DNS lookups */
108         c_resolv_cb = create_preference_check_button(main_tb, 3,
109             "Enable concurrent DNS name resolution:", "be sure to enable network name resolution",
110             prefs.name_resolve & RESOLV_CONCURRENT);
111         OBJECT_SET_DATA(main_vb, C_RESOLVE_KEY, c_resolv_cb);
112
113         /* Max concurrent requests */
114         g_snprintf(concur_str, 10+1, "%d", prefs.name_resolve_concurrency);
115         resolv_concurrency_te = create_preference_entry(main_tb, 4, 
116             "Maximum concurrent requests:", "maximum parallel running DNS requests", concur_str);
117         OBJECT_SET_DATA(main_vb, RESOLVE_CONCURRENCY_KEY, resolv_concurrency_te);
118
119 #endif /* HAVE_GNU_ADNS */
120
121         /* Show 'em what we got */
122         gtk_widget_show_all(main_vb);
123
124         return(main_vb);
125 }
126
127 void
128 nameres_prefs_fetch(GtkWidget *w)
129 {
130         GtkWidget *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
131 #ifdef HAVE_GNU_ADNS
132         GtkWidget *c_resolv_cb, *resolv_concurrency_te;
133 #endif /* HAVE_GNU_ADNS */
134
135         m_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, M_RESOLVE_KEY);
136         n_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, N_RESOLVE_KEY);
137         t_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, T_RESOLVE_KEY);
138 #ifdef HAVE_GNU_ADNS
139         c_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, C_RESOLVE_KEY);
140         
141         resolv_concurrency_te = (GtkWidget *)OBJECT_GET_DATA(w, RESOLVE_CONCURRENCY_KEY);
142 #endif /* HAVE_GNU_ADNS */
143
144         prefs.name_resolve = RESOLV_NONE;
145         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? RESOLV_MAC : RESOLV_NONE);
146         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? RESOLV_NETWORK : RESOLV_NONE);
147         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? RESOLV_TRANSPORT : RESOLV_NONE);
148 #ifdef HAVE_GNU_ADNS
149         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (c_resolv_cb)->active ? RESOLV_CONCURRENT : RESOLV_NONE);
150
151         prefs.name_resolve_concurrency = strtol (gtk_entry_get_text(
152                 GTK_ENTRY(resolv_concurrency_te)), NULL, 10);
153 #endif /* HAVE_GNU_ADNS */
154 }
155
156 void
157 nameres_prefs_apply(GtkWidget *w _U_)
158 {
159         /*
160          * XXX - force a regeneration of the protocol list if this has
161          * changed?
162          */
163         g_resolv_flags = prefs.name_resolve;
164     menu_name_resolution_changed();
165 }
166
167 void
168 nameres_prefs_destroy(GtkWidget *w _U_)
169 {
170 }