"main_menu.[ch]" -> "menus.[ch]"; it handles not only the main menu, but
[obnox/wireshark/wip.git] / gtk / prefs_nameres.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 <epan/addr_resolv.h>
32 #include <epan/prefs.h>
33 #include <epan/uat.h>
34
35 #include "../globals.h"
36
37 #include "gtk/prefs_nameres.h"
38 #include "gtk/gtkglobals.h"
39 #include "gtk/prefs_dlg.h"
40 #include "gtk/gui_utils.h"
41 #include "gtk/main.h"
42 #include "gtk/menus.h"
43
44
45 #define M_RESOLVE_KEY   "m_resolve"
46 #define N_RESOLVE_KEY   "n_resolve"
47 #define T_RESOLVE_KEY   "t_resolve"
48
49 #if defined(HAVE_C_ARES) || defined(HAVE_GNU_ADNS)
50 # define C_RESOLVE_KEY  "c_resolve"
51 # define RESOLVE_CONCURRENCY_KEY "resolve_concurrency"
52 #endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
53
54 #ifdef HAVE_LIBSMI
55 # define SP_RESOLVE_KEY "sp_resolve"
56 # define SM_RESOLVE_KEY "sm_resolve"
57 #endif /* HAVE_LIBSMI */
58
59 #ifdef HAVE_GEOIP
60 # define GEOIP_RESOLVE_KEY "geoip_resolve"
61 #endif /* HAVE_GEOIP */
62
63 #define BASE_TABLE_ROWS 3
64
65 #if defined(HAVE_C_ARES) || defined(HAVE_GNU_ADNS)
66 # define ASYNC_TABLE_ROWS 2
67 #else
68 # define ASYNC_TABLE_ROWS 0
69 #endif
70
71 #ifdef HAVE_LIBSMI
72 # define SMI_TABLE_ROWS 2
73 #else
74 # define SMI_TABLE_ROWS 0
75 #endif
76
77 #ifdef HAVE_GEOIP
78 # define GEOIP_TABLE_ROWS 1
79 #else
80 # define GEOIP_TABLE_ROWS 0
81 #endif
82
83 #define RESOLV_TABLE_ROWS (\
84         BASE_TABLE_ROWS + \
85         ASYNC_TABLE_ROWS + \
86         SMI_TABLE_ROWS + \
87         GEOIP_TABLE_ROWS \
88         )
89
90 GtkWidget*
91 nameres_prefs_show(void)
92 {
93         guint           table_row;
94         GtkWidget       *main_tb, *main_vb;
95         GtkWidget       *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
96         GtkTooltips *tooltips = gtk_tooltips_new();
97         GtkWidget       *c_resolv_cb;
98 #if defined(HAVE_C_ARES) || defined(HAVE_GNU_ADNS)
99         GtkWidget       *resolv_concurrency_te;
100         char            concur_str[10+1];
101 #endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
102         GtkWidget       *sm_resolv_bt;
103 #ifdef HAVE_LIBSMI
104         GtkWidget       *sp_resolv_bt;
105         uat_t *smi_paths_uat;
106         uat_t *smi_modules_uat;
107 #endif
108         GtkWidget       *geoip_resolv_bt;
109 #ifdef HAVE_GEOIP
110         uat_t           *geoip_db_paths_uat;
111 #endif
112         /*
113          * XXX - it would be nice if the current setting of the resolver
114          * flags could be different from the preference flags, so that
115          * the preference flags would represent what the user *typically*
116          * wants, but they could override them for particular captures
117          * without a subsequent editing of the preferences recording the
118          * temporary settings as permanent preferences.
119          */
120         prefs.name_resolve = g_resolv_flags;
121
122         /* Main vertical box */
123         main_vb = gtk_vbox_new(FALSE, 7);
124         gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
125
126         /* Main table */
127         main_tb = gtk_table_new(RESOLV_TABLE_ROWS, 3, FALSE);
128         gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
129         gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
130         gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
131         gtk_widget_show(main_tb);
132         g_object_set_data(G_OBJECT(main_tb), E_TOOLTIPS_KEY, tooltips);
133
134         /* Resolve MAC addresses */
135         table_row = 0;
136         m_resolv_cb = create_preference_check_button(main_tb, table_row,
137             "Enable MAC name resolution:", "e.g. Ethernet address to manufacturer name",
138             prefs.name_resolve & RESOLV_MAC);
139         g_object_set_data(G_OBJECT(main_vb), M_RESOLVE_KEY, m_resolv_cb);
140
141         /* Resolve network addresses */
142         table_row++;
143         n_resolv_cb = create_preference_check_button(main_tb, table_row,
144             "Enable network name resolution:", "e.g. IP address to DNS name (hostname)",
145             prefs.name_resolve & RESOLV_NETWORK);
146         g_object_set_data(G_OBJECT(main_vb), N_RESOLVE_KEY, n_resolv_cb);
147
148         /* Resolve transport addresses */
149         table_row++;
150         t_resolv_cb = create_preference_check_button(main_tb, table_row,
151             "Enable transport name resolution:", "e.g. TCP/UDP port to service name",
152             prefs.name_resolve & RESOLV_TRANSPORT);
153         g_object_set_data(G_OBJECT(main_vb), T_RESOLVE_KEY, t_resolv_cb);
154
155 #if defined(HAVE_C_ARES) || defined(HAVE_GNU_ADNS)
156         /* Enable concurrent (asynchronous) DNS lookups */
157         table_row++;
158         c_resolv_cb = create_preference_check_button(main_tb, table_row,
159             "Enable concurrent DNS name resolution:", "be sure to enable network name resolution",
160             prefs.name_resolve & RESOLV_CONCURRENT);
161         g_object_set_data(G_OBJECT(main_vb), C_RESOLVE_KEY, c_resolv_cb);
162
163         /* Max concurrent requests */
164         table_row++;
165         g_snprintf(concur_str, sizeof(concur_str), "%d", prefs.name_resolve_concurrency);
166         resolv_concurrency_te = create_preference_entry(main_tb, table_row,
167             "Maximum concurrent requests:", "maximum parallel running DNS requests", concur_str);
168         g_object_set_data(G_OBJECT(main_vb), RESOLVE_CONCURRENCY_KEY, resolv_concurrency_te);
169
170 #else /* HAVE_C_ARES || HAVE_GNU_ADNS */
171         table_row++;
172         c_resolv_cb = create_preference_static_text(main_tb, table_row,
173             "Enable concurrent DNS name resolution: N/A",
174             "Support for this feature was not compiled into this version of Wireshark");
175 #endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
176 #ifdef HAVE_LIBSMI
177         /* SMI paths UAT */
178         smi_paths_uat = uat_get_table_by_name("SMI Paths");
179         if (smi_paths_uat) {
180                 table_row++;
181                 sp_resolv_bt = create_preference_uat(main_tb, table_row,
182                     "SMI (MIB and PIB) paths",
183                     "Search paths for SMI (MIB and PIB) modules. You must\n"
184                     "restart Wireshark for these changes to take effect.",
185                     smi_paths_uat);
186                 g_object_set_data(G_OBJECT(main_vb), SP_RESOLVE_KEY, sp_resolv_bt);
187         }
188
189         /* SMI modules UAT */
190         smi_modules_uat = uat_get_table_by_name("SMI Modules");
191         if (smi_modules_uat) {
192                 table_row++;
193                 sm_resolv_bt = create_preference_uat(main_tb, table_row,
194                     "SMI (MIB and PIB) modules",
195                     "List of enabled SMI (MIB and PIB) modules. You must\n"
196                     "restart Wireshark for these changes to take effect.",
197                     smi_modules_uat);
198                 g_object_set_data(G_OBJECT(main_vb), SM_RESOLVE_KEY, sm_resolv_bt);
199         }
200 #else /* HAVE_LIBSMI */
201         table_row++;
202         sm_resolv_bt = create_preference_static_text(main_tb, table_row,
203             "SMI (MIB and PIB) modules and paths: N/A",
204             "Support for this feature was not compiled into this version of Wireshark");
205 #endif /* HAVE_LIBSMI */
206
207 #ifdef HAVE_GEOIP
208         /* GeoIP databases http://www.maxmind.com/app/api */
209         geoip_db_paths_uat = uat_get_table_by_name("GeoIP Database Paths");
210
211         if (geoip_db_paths_uat) {
212                 table_row++;
213                 geoip_resolv_bt = create_preference_uat(main_tb, table_row,
214                     "GeoIP database directories",
215                     "Search paths for GeoIP address mapping databases.\n"
216                     "Wireshark will look in each directory for files beginning\n"
217                     "with \"Geo\" and ending with \".dat\".\n"
218                     "You must restart Wireshark for these changes to take\n"
219                     "effect.",
220                     geoip_db_paths_uat);
221                 g_object_set_data(G_OBJECT(main_vb), GEOIP_RESOLVE_KEY, geoip_resolv_bt);
222         }
223 #else /* HAVE_GEOIP */
224         table_row++;
225         geoip_resolv_bt = create_preference_static_text(main_tb, table_row,
226             "GeoIP database search paths: N/A",
227             "Support for this feature was not compiled into this version of Wireshark");
228 #endif /* HAVE_GEOIP */
229
230         /* Show 'em what we got */
231         gtk_widget_show_all(main_vb);
232
233         return(main_vb);
234 }
235
236 void
237 nameres_prefs_fetch(GtkWidget *w)
238 {
239         GtkWidget *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
240 #if defined(HAVE_C_ARES) || defined(HAVE_GNU_ADNS)
241         GtkWidget *c_resolv_cb, *resolv_concurrency_te;
242 #endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
243 #ifdef HAVE_LIBSMI
244         GtkWidget *sp_resolv_bt, *sm_resolv_bt;
245 #endif
246 #ifdef HAVE_GEOIP
247         GtkWidget *geoip_resolv_bt;
248 #endif
249
250         m_resolv_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), M_RESOLVE_KEY);
251         n_resolv_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), N_RESOLVE_KEY);
252         t_resolv_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), T_RESOLVE_KEY);
253 #if defined(HAVE_C_ARES) || defined(HAVE_GNU_ADNS)
254         c_resolv_cb = (GtkWidget *)g_object_get_data(G_OBJECT(w), C_RESOLVE_KEY);
255
256         resolv_concurrency_te = (GtkWidget *)g_object_get_data(G_OBJECT(w), RESOLVE_CONCURRENCY_KEY);
257 #endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
258 #ifdef HAVE_LIBSMI
259         sp_resolv_bt = (GtkWidget *)g_object_get_data(G_OBJECT(w), SP_RESOLVE_KEY);
260         sm_resolv_bt = (GtkWidget *)g_object_get_data(G_OBJECT(w), SM_RESOLVE_KEY);
261 #endif
262 #ifdef HAVE_GEOIP
263         geoip_resolv_bt = (GtkWidget *)g_object_get_data(G_OBJECT(w), GEOIP_RESOLVE_KEY);
264 #endif
265
266         prefs.name_resolve = RESOLV_NONE;
267         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (m_resolv_cb)->active ? RESOLV_MAC : RESOLV_NONE);
268         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (n_resolv_cb)->active ? RESOLV_NETWORK : RESOLV_NONE);
269         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (t_resolv_cb)->active ? RESOLV_TRANSPORT : RESOLV_NONE);
270 #if defined(HAVE_C_ARES) || defined(HAVE_GNU_ADNS)
271         prefs.name_resolve |= (GTK_TOGGLE_BUTTON (c_resolv_cb)->active ? RESOLV_CONCURRENT : RESOLV_NONE);
272
273         prefs.name_resolve_concurrency = strtol (gtk_entry_get_text(
274                 GTK_ENTRY(resolv_concurrency_te)), NULL, 10);
275 #endif /* HAVE_C_ARES || HAVE_GNU_ADNS */
276 }
277
278 void
279 nameres_prefs_apply(GtkWidget *w _U_)
280 {
281         /*
282          * XXX - force a regeneration of the protocol list if this has
283          * changed?
284          */
285         g_resolv_flags = prefs.name_resolve;
286         menu_name_resolution_changed();
287 }
288
289 void
290 nameres_prefs_destroy(GtkWidget *w _U_)
291 {
292 }