Move libsmi settings from virtual mibs protocol page to name resolution page.
[obnox/wireshark/wip.git] / gtk / nameres_prefs.c
1 /* nameres_prefs.c
2  * Dialog box for name resolution preferences
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 <epan/uat.h>
37 #include "prefs_dlg.h"
38 #include "gui_utils.h"
39 #include "main.h"
40 #include "menu.h"
41 #include "compat_macros.h"
42
43 #define M_RESOLVE_KEY   "m_resolve"
44 #define N_RESOLVE_KEY   "n_resolve"
45 #define T_RESOLVE_KEY   "t_resolve"
46 #ifdef HAVE_GNU_ADNS
47 # define C_RESOLVE_KEY  "c_resolve"
48 # define RESOLVE_CONCURRENCY_KEY "resolve_concurrency"
49 #endif /* HAVE_GNU_ADNS */
50 #ifdef HAVE_LIBSMI
51 #define SP_RESOLVE_KEY  "sp_resolve"
52 #define SM_RESOLVE_KEY  "sm_resolve"
53 extern uat_t *smi_paths_uat;
54 extern uat_t *smi_modules_uat;
55 #endif
56
57 #ifdef HAVE_GNU_ADNS
58 # ifdef HAVE_LIBSMI
59 #  define RESOLV_TABLE_ROWS 7
60 # else
61 #  define RESOLV_TABLE_ROWS 5
62 # endif
63 #else
64 # ifdef HAVE_LIBSMI
65 #  define RESOLV_TABLE_ROWS 5
66 # else
67 #  define RESOLV_TABLE_ROWS 3
68 # endif
69 #endif /* HAVE_GNU_ADNS */
70 GtkWidget*
71 nameres_prefs_show(void)
72 {
73         guint           table_row;
74         GtkWidget       *main_tb, *main_vb;
75         GtkWidget       *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
76         GtkTooltips *tooltips = gtk_tooltips_new();
77 #ifdef HAVE_GNU_ADNS
78         GtkWidget       *c_resolv_cb, *resolv_concurrency_te;
79         char            concur_str[10+1];
80 #endif /* HAVE_GNU_ADNS */
81 #ifdef HAVE_LIBSMI
82         GtkWidget       *sp_resolv_cb, *sm_resolv_cb;
83 #endif
84         /*
85          * XXX - it would be nice if the current setting of the resolver
86          * flags could be different from the preference flags, so that
87          * the preference flags would represent what the user *typically*
88          * wants, but they could override them for particular captures
89          * without a subsequent editing of the preferences recording the
90          * temporary settings as permanent preferences.
91          */
92         prefs.name_resolve = g_resolv_flags;
93
94         /* Main vertical box */
95         main_vb = gtk_vbox_new(FALSE, 7);
96         gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
97
98         /* Main table */
99         main_tb = gtk_table_new(RESOLV_TABLE_ROWS, 3, FALSE);
100         gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
101         gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
102         gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
103         gtk_widget_show(main_tb);
104         OBJECT_SET_DATA(main_tb, E_TOOLTIPS_KEY, tooltips);
105
106         /* Resolve MAC addresses */
107         table_row = 0;
108         m_resolv_cb = create_preference_check_button(main_tb, table_row,
109             "Enable MAC name resolution:", "e.g. Ethernet address to manufacturer name",
110             prefs.name_resolve & RESOLV_MAC);
111         OBJECT_SET_DATA(main_vb, M_RESOLVE_KEY, m_resolv_cb);
112
113         /* Resolve network addresses */
114         table_row++;
115         n_resolv_cb = create_preference_check_button(main_tb, table_row,
116             "Enable network name resolution:", "e.g. IP address to DNS name (hostname)",
117             prefs.name_resolve & RESOLV_NETWORK);
118         OBJECT_SET_DATA(main_vb, N_RESOLVE_KEY, n_resolv_cb);
119
120         /* Resolve transport addresses */
121         table_row++;
122         t_resolv_cb = create_preference_check_button(main_tb, table_row,
123             "Enable transport name resolution:", "e.g. TCP/UDP port to service name",
124             prefs.name_resolve & RESOLV_TRANSPORT);
125         OBJECT_SET_DATA(main_vb, T_RESOLVE_KEY, t_resolv_cb);
126
127 #ifdef HAVE_GNU_ADNS
128         /* Enable concurrent (asynchronous) DNS lookups */
129         table_row++;
130         c_resolv_cb = create_preference_check_button(main_tb, table_row,
131             "Enable concurrent DNS name resolution:", "be sure to enable network name resolution",
132             prefs.name_resolve & RESOLV_CONCURRENT);
133         OBJECT_SET_DATA(main_vb, C_RESOLVE_KEY, c_resolv_cb);
134
135         /* Max concurrent requests */
136         table_row++;
137         g_snprintf(concur_str, 10+1, "%d", prefs.name_resolve_concurrency);
138         resolv_concurrency_te = create_preference_entry(main_tb, table_row, 
139             "Maximum concurrent requests:", "maximum parallel running DNS requests", concur_str);
140         OBJECT_SET_DATA(main_vb, RESOLVE_CONCURRENCY_KEY, resolv_concurrency_te);
141
142 #endif /* HAVE_GNU_ADNS */
143 #ifdef HAVE_LIBSMI
144         /* SMI paths UAT */
145         table_row++;
146         sp_resolv_cb = create_preference_uat(main_tb, table_row,
147             "SMI paths", "SMI paths to MIBS", smi_paths_uat);
148         OBJECT_SET_DATA(main_vb, SP_RESOLVE_KEY, sp_resolv_cb);
149
150         /* SMI modules UAT */
151         table_row++;
152         sm_resolv_cb = create_preference_uat(main_tb, table_row,
153             "SMI modules", "SMI list of modules", smi_modules_uat);
154         OBJECT_SET_DATA(main_vb, SM_RESOLVE_KEY, sm_resolv_cb);
155 #endif
156
157         /* Show 'em what we got */
158         gtk_widget_show_all(main_vb);
159
160         return(main_vb);
161 }
162
163 void
164 nameres_prefs_fetch(GtkWidget *w)
165 {
166         GtkWidget *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
167 #ifdef HAVE_GNU_ADNS
168         GtkWidget *c_resolv_cb, *resolv_concurrency_te;
169 #endif /* HAVE_GNU_ADNS */
170 #ifdef HAVE_LIBSMI
171         GtkWidget *sp_resolv_cb, *sm_resolv_cb;
172 #endif
173
174         m_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, M_RESOLVE_KEY);
175         n_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, N_RESOLVE_KEY);
176         t_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, T_RESOLVE_KEY);
177 #ifdef HAVE_GNU_ADNS
178         c_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, C_RESOLVE_KEY);
179         
180         resolv_concurrency_te = (GtkWidget *)OBJECT_GET_DATA(w, RESOLVE_CONCURRENCY_KEY);
181 #endif /* HAVE_GNU_ADNS */
182 #ifdef HAVE_LIBSMI
183         sp_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, SP_RESOLVE_KEY);
184         sm_resolv_cb = (GtkWidget *)OBJECT_GET_DATA(w, SM_RESOLVE_KEY);
185 #endif
186
187         prefs.name_resolve = RESOLV_NONE;
188         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? RESOLV_MAC : RESOLV_NONE);
189         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? RESOLV_NETWORK : RESOLV_NONE);
190         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? RESOLV_TRANSPORT : RESOLV_NONE);
191 #ifdef HAVE_GNU_ADNS
192         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (c_resolv_cb)->active ? RESOLV_CONCURRENT : RESOLV_NONE);
193
194         prefs.name_resolve_concurrency = strtol (gtk_entry_get_text(
195                 GTK_ENTRY(resolv_concurrency_te)), NULL, 10);
196 #endif /* HAVE_GNU_ADNS */
197 }
198
199 void
200 nameres_prefs_apply(GtkWidget *w _U_)
201 {
202         /*
203          * XXX - force a regeneration of the protocol list if this has
204          * changed?
205          */
206         g_resolv_flags = prefs.name_resolve;
207         menu_name_resolution_changed();
208 }
209
210 void
211 nameres_prefs_destroy(GtkWidget *w _U_)
212 {
213 }