name change
[obnox/wireshark/wip.git] / asn1 / ocsp / packet-ocsp-template.c
1 /* packet-ocsp.c
2  * Routines for Online Certificate Status Protocol (RFC2560) 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
33 #include <stdio.h>
34 #include <string.h>
35
36 #include "packet-ber.h"
37 #include "packet-ocsp.h"
38 #include "packet-x509af.h"
39 #include "packet-x509ce.h"
40 #include "packet-pkix1implicit.h"
41 #include "packet-pkix1explicit.h"
42
43 #define PNAME  "Online Certificate Status Protocol"
44 #define PSNAME "OCSP"
45 #define PFNAME "ocsp"
46
47 /* Initialize the protocol and registered fields */
48 static int proto_ocsp = -1;
49 static int hf_ocsp_responseType_id = -1;
50 #include "packet-ocsp-hf.c"
51
52 /* Initialize the subtree pointers */
53 static gint ett_ocsp = -1;
54 #include "packet-ocsp-ett.c"
55
56 static const char *responseType_id;
57
58
59 #include "packet-ocsp-fn.c"
60
61
62 static int
63 dissect_ocsp_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
64 {
65         proto_item *item=NULL;
66         proto_tree *tree=NULL;
67
68         if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
69                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OCSP");
70
71         if (check_col(pinfo->cinfo, COL_INFO)) {
72                 col_clear(pinfo->cinfo, COL_INFO);
73                 
74                 col_add_fstr(pinfo->cinfo, COL_INFO, "Request");
75         }
76
77
78         if(parent_tree){
79                 item=proto_tree_add_item(parent_tree, proto_ocsp, tvb, 0, -1, FALSE);
80                 tree = proto_item_add_subtree(item, ett_ocsp);
81         }
82
83         return dissect_ocsp_OCSPRequest(FALSE, tvb, 0, pinfo, tree, -1);
84 }
85
86
87 static int
88 dissect_ocsp_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
89 {
90         proto_item *item=NULL;
91         proto_tree *tree=NULL;
92
93         if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
94                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OCSP");
95
96         if (check_col(pinfo->cinfo, COL_INFO)) {
97                 col_clear(pinfo->cinfo, COL_INFO);
98                 
99                 col_add_fstr(pinfo->cinfo, COL_INFO, "Response");
100         }
101
102
103         if(parent_tree){
104                 item=proto_tree_add_item(parent_tree, proto_ocsp, tvb, 0, -1, FALSE);
105                 tree = proto_item_add_subtree(item, ett_ocsp);
106         }
107
108         return dissect_ocsp_OCSPResponse(FALSE, tvb, 0, pinfo, tree, -1);
109 }
110
111 /*--- proto_register_ocsp ----------------------------------------------*/
112 void proto_register_ocsp(void) {
113
114   /* List of fields */
115   static hf_register_info hf[] = {
116     { &hf_ocsp_responseType_id,
117       { "ResponseType Id", "x509af.responseType.id",
118         FT_STRING, BASE_NONE, NULL, 0,
119         "ResponseType Id", HFILL }},
120 #include "packet-ocsp-hfarr.c"
121   };
122
123   /* List of subtrees */
124   static gint *ett[] = {
125     &ett_ocsp,
126 #include "packet-ocsp-ettarr.c"
127   };
128
129   /* Register protocol */
130   proto_ocsp = proto_register_protocol(PNAME, PSNAME, PFNAME);
131
132   /* Register fields and subtrees */
133   proto_register_field_array(proto_ocsp, hf, array_length(hf));
134   proto_register_subtree_array(ett, array_length(ett));
135
136 }
137
138 /*--- proto_reg_handoff_ocsp -------------------------------------------*/
139 void proto_reg_handoff_ocsp(void) {
140         dissector_handle_t ocsp_request_handle;
141         dissector_handle_t ocsp_response_handle;
142
143         ocsp_request_handle = new_create_dissector_handle(dissect_ocsp_request, proto_ocsp);
144         ocsp_response_handle = new_create_dissector_handle(dissect_ocsp_response, proto_ocsp);
145
146         dissector_add_string("media_type", "application/ocsp-request", ocsp_request_handle);
147         dissector_add_string("media_type", "application/ocsp-response", ocsp_response_handle);
148
149 #include "packet-ocsp-dis-tab.c"
150 }
151