Detect clang and llvm-gcc.
[obnox/wireshark/wip.git] / gtk / decode_as_ber.c
1 /* decode_as_ber.c
2  *
3  * $Id$
4  *
5  * Routines to modify BER decoding on the fly.
6  *
7  * Copyright 2006 Graeme Lunt
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27 #include <string.h>
28
29 #include <gtk/gtk.h>
30
31 #include <epan/packet.h>
32 #include <epan/epan_dissect.h>
33 #include <epan/dissectors/packet-ber.h>
34
35 #include "../globals.h"
36 #include "../simple_dialog.h"
37
38 #include "gtk/decode_as_dlg.h"
39 #include "gtk/dlg_utils.h"
40 #include "gtk/gui_utils.h"
41 #include "gtk/decode_as_dcerpc.h"
42 #include "gtk/decode_as_ber.h"
43
44
45 /**************************************************/
46 /* Action routines for the "Decode As..." dialog  */
47 /*   - called when the OK button pressed          */
48 /**************************************************/
49
50 /*
51  * This routine is called when the user clicks the "OK" button in the
52  * "Decode As..." dialog window and the ASN.1 page is foremost.
53  * This routine takes care of making any changes requested to the ASN.1  
54  * decoding.
55  *
56  * @param notebook_pg A pointer to the "ASN.1" notebook page.
57  */
58 static void
59 decode_ber(GtkWidget *notebook_pg)
60 {
61     GtkWidget *list;
62     gchar              *syntax;
63     GtkTreeSelection  *selection;
64     GtkTreeModel      *model;
65     GtkTreeIter        iter;
66
67     syntax = NULL;
68     list = g_object_get_data(G_OBJECT(notebook_pg), E_PAGE_LIST);
69
70     if (requested_action == E_DECODE_NO)
71         gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(list)));
72
73     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
74     if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE)
75     {
76         syntax = NULL;
77     } else {
78       gtk_tree_model_get(model, &iter, E_LIST_S_PROTO_NAME, &syntax, -1);
79     }
80
81     if ((syntax != NULL && strcmp(syntax, "(default)") == 0) ) {
82       ber_decode_as(NULL);
83     } else {
84       ber_decode_as(syntax);
85     }
86     g_free(syntax);
87 }
88
89
90 /**************************************************/
91 /*                  Dialog setup                  */
92 /**************************************************/
93
94
95 /* add an interface to the list */
96 static void 
97 decode_ber_add_to_list(gpointer key, gpointer value, gpointer user_data)
98 {
99     decode_add_to_list("ASN.1", key, value, user_data);
100 }
101
102
103 /* add all interfaces to the list */
104 static GtkWidget *
105 decode_add_ber_menu (GtkWidget *page, const gchar *table_name _U_)
106 {
107     GtkWidget *scrolled_window;
108     GtkWidget *list;
109
110     decode_list_menu_start(page, &list, &scrolled_window);
111
112     ber_decode_as_foreach(decode_ber_add_to_list, list);
113     decode_list_menu_finish(list);
114     return(scrolled_window);
115 }
116
117
118 /* add a BER page to the notebook */
119 GtkWidget *
120 decode_ber_add_page (packet_info *pinfo _U_)
121 {
122     GtkWidget   *page_hb, *info_vb, *label, *scrolled_window;
123
124     /* create page content */
125     page_hb = gtk_hbox_new(FALSE, 5);
126     g_object_set_data(G_OBJECT(page_hb), E_PAGE_ACTION, decode_ber);
127     g_object_set_data(G_OBJECT(page_hb), E_PAGE_TABLE, "ASN.1");
128     g_object_set_data(G_OBJECT(page_hb), E_PAGE_TITLE, "ASN.1");
129     
130     info_vb = gtk_vbox_new(FALSE, 5);
131     gtk_box_pack_start(GTK_BOX(page_hb), info_vb, TRUE, TRUE, 0);
132
133     /* Always enabled */
134     label = gtk_label_new("Decode ASN.1 file as:");
135     gtk_box_pack_start(GTK_BOX(info_vb), label, TRUE, TRUE, 0);
136
137     scrolled_window = decode_add_ber_menu(page_hb, "ber" /*table_name*/);
138     gtk_box_pack_start(GTK_BOX(page_hb), scrolled_window, TRUE, TRUE, 0);
139     decode_dimmable = g_slist_prepend(decode_dimmable, scrolled_window);
140
141     return(page_hb);
142 }