Second step in introducing asn context to BER dissectors just like in PER.
[obnox/wireshark/wip.git] / asn1 / x509if / packet-x509if-template.c
1 /* packet-x509if.c
2  * Routines for X.509 Information Framework packet dissection
3  *  Ronnie Sahlberg 2004
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/conversation.h>
33 #include <epan/oid_resolv.h>
34 #include <epan/asn1.h>
35
36 #include <stdio.h>
37 #include <string.h>
38
39 #include "packet-ber.h"
40 #include "packet-x509if.h"
41 #include "packet-x509sat.h"
42 #include <epan/emem.h>
43 #include <epan/strutil.h>
44
45 #define PNAME  "X.509 Information Framework"
46 #define PSNAME "X509IF"
47 #define PFNAME "x509if"
48
49 /* Initialize the protocol and registered fields */
50 int proto_x509if = -1;
51 static int hf_x509if_object_identifier_id = -1;
52 static int hf_x509if_any_string = -1;
53 #include "packet-x509if-hf.c"
54
55 /* Initialize the subtree pointers */
56 #include "packet-x509if-ett.c"
57
58 static const char *object_identifier_id;
59 static proto_tree *top_of_dn = NULL;
60 static proto_tree *top_of_rdn = NULL;
61
62 static gboolean rdn_one_value = FALSE; /* have we seen one value in an RDN yet */
63 static gboolean dn_one_rdn = FALSE; /* have we seen one RDN in a DN yet */
64 static gboolean doing_dn = TRUE;
65
66 #define MAX_RDN_STR_LEN   64
67 #define MAX_DN_STR_LEN    (20 * MAX_RDN_STR_LEN)
68
69 static char *last_dn = NULL;
70 static char *last_rdn = NULL;
71
72 static int ava_hf_index;
73 #define MAX_FMT_VALS   32
74 static value_string fmt_vals[MAX_FMT_VALS];
75 #define MAX_AVA_STR_LEN   64
76 static char *last_ava = NULL;
77
78 #include "packet-x509if-fn.c"
79
80 const char * x509if_get_last_dn(void)
81 {
82   return last_dn;
83 }
84
85 gboolean x509if_register_fmt(int hf_index, const gchar *fmt)
86 {
87   static int idx = 0;
88
89   if(idx < (MAX_FMT_VALS - 1)) {
90
91     fmt_vals[idx].value = hf_index;
92     fmt_vals[idx].strptr = fmt;
93
94     idx++;
95
96     fmt_vals[idx].value = 0;
97     fmt_vals[idx].strptr = NULL;
98
99     return TRUE;
100
101   } else 
102     return FALSE; /* couldn't register it */
103
104 }
105
106 const char * x509if_get_last_ava(void)
107 {
108   return last_ava;
109 }
110
111 /*--- proto_register_x509if ----------------------------------------------*/
112 void proto_register_x509if(void) {
113
114   /* List of fields */
115   static hf_register_info hf[] = {
116     { &hf_x509if_object_identifier_id, 
117       { "Id", "x509if.id", FT_OID, BASE_NONE, NULL, 0,
118         "Object identifier Id", HFILL }},
119     { &hf_x509if_any_string, 
120       { "AnyString", "x509if.any.String", FT_BYTES, BASE_HEX,
121             NULL, 0, "This is any String", HFILL }},
122                          
123 #include "packet-x509if-hfarr.c"
124   };
125
126   /* List of subtrees */
127   static gint *ett[] = {
128 #include "packet-x509if-ettarr.c"
129   };
130
131   /* Register protocol */
132   proto_x509if = proto_register_protocol(PNAME, PSNAME, PFNAME);
133
134   /* Register fields and subtrees */
135   proto_register_field_array(proto_x509if, hf, array_length(hf));
136   proto_register_subtree_array(ett, array_length(ett));
137
138   /* initialise array */
139   fmt_vals[0].value = 0;
140   fmt_vals[0].strptr = NULL;
141
142 }
143
144
145 /*--- proto_reg_handoff_x509if -------------------------------------------*/
146 void proto_reg_handoff_x509if(void) {
147 #include "packet-x509if-dis-tab.c"
148 }
149