2c38b0b909013d7e199b69abd7bb14173a784c72
[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/oids.h>
33 #include <epan/asn1.h>
34
35 #include "packet-ber.h"
36 #include "packet-dap.h"
37 #include "packet-x509if.h"
38 #include "packet-x509sat.h"
39 #include <epan/strutil.h>
40
41 #define PNAME  "X.509 Information Framework"
42 #define PSNAME "X509IF"
43 #define PFNAME "x509if"
44
45 /* Initialize the protocol and registered fields */
46 static int proto_x509if = -1;
47 static int hf_x509if_object_identifier_id = -1;
48 static int hf_x509if_any_string = -1;
49 #include "packet-x509if-hf.c"
50
51 /* Initialize the subtree pointers */
52 #include "packet-x509if-ett.c"
53
54 static const char *object_identifier_id;
55 static proto_tree *top_of_dn = NULL;
56 static proto_tree *top_of_rdn = NULL;
57
58 static gboolean rdn_one_value = FALSE; /* have we seen one value in an RDN yet */
59 static gboolean dn_one_rdn = FALSE; /* have we seen one RDN in a DN yet */
60 static gboolean doing_dn = TRUE;
61 static gboolean doing_attr = FALSE;
62
63 #define MAX_RDN_STR_LEN   64
64 #define MAX_DN_STR_LEN    (20 * MAX_RDN_STR_LEN)
65
66 static char *last_dn = NULL;
67 static char *last_rdn = NULL;
68
69 static int ava_hf_index;
70 #define MAX_FMT_VALS   32
71 static value_string fmt_vals[MAX_FMT_VALS];
72 #define MAX_AVA_STR_LEN   64
73 static char *last_ava = NULL;
74
75 #include "packet-x509if-fn.c"
76
77 const char * x509if_get_last_dn(void)
78 {
79   return last_dn;
80 }
81
82 gboolean x509if_register_fmt(int hf_index, const gchar *fmt)
83 {
84   static int idx = 0;
85
86   if(idx < (MAX_FMT_VALS - 1)) {
87
88     fmt_vals[idx].value = hf_index;
89     fmt_vals[idx].strptr = fmt;
90
91     idx++;
92
93     fmt_vals[idx].value = 0;
94     fmt_vals[idx].strptr = NULL;
95
96     return TRUE;
97
98   } else 
99     return FALSE; /* couldn't register it */
100
101 }
102
103 const char * x509if_get_last_ava(void)
104 {
105   return last_ava;
106 }
107
108 /*--- proto_register_x509if ----------------------------------------------*/
109 void proto_register_x509if(void) {
110
111   /* List of fields */
112   static hf_register_info hf[] = {
113     { &hf_x509if_object_identifier_id, 
114       { "Id", "x509if.id", FT_OID, BASE_NONE, NULL, 0,
115         "Object identifier Id", HFILL }},
116     { &hf_x509if_any_string, 
117       { "AnyString", "x509if.any.String", FT_BYTES, BASE_NONE,
118             NULL, 0, "This is any String", HFILL }},
119                          
120 #include "packet-x509if-hfarr.c"
121   };
122
123   /* List of subtrees */
124   static gint *ett[] = {
125 #include "packet-x509if-ettarr.c"
126   };
127
128   /* Register protocol */
129   proto_x509if = proto_register_protocol(PNAME, PSNAME, PFNAME);
130
131   /* Register fields and subtrees */
132   proto_register_field_array(proto_x509if, hf, array_length(hf));
133   proto_register_subtree_array(ett, array_length(ett));
134
135   /* initialise array */
136   fmt_vals[0].value = 0;
137   fmt_vals[0].strptr = NULL;
138
139 }
140
141
142 /*--- proto_reg_handoff_x509if -------------------------------------------*/
143 void proto_reg_handoff_x509if(void) {
144 #include "packet-x509if-dis-tab.c"
145 }
146