Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-acap.c
blobe253fb10c28f23d96f71289cff5245b98f2ca019
1 /* packet-acap.c
2 * Routines for ACAP packet dissection
3 * RFC 2244
4 * Copyright 2003, Brad Hards <bradh@frogmouth.net>
5 * Heavily based in packet-imap.c, Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-imap.c
13 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include "config.h"
17 #include <epan/packet.h>
18 #include <epan/strutil.h>
20 /* Forward declarations */
21 void proto_register_acap(void);
22 void proto_reg_handoff_acap(void);
24 static dissector_handle_t acap_handle;
26 static int proto_acap;
28 static int hf_acap_request;
29 static int hf_acap_request_data;
30 static int hf_acap_request_tag;
31 static int hf_acap_response;
32 static int hf_acap_response_data;
33 static int hf_acap_response_tag;
35 static int ett_acap;
36 static int ett_acap_reqresp;
38 #define TCP_PORT_ACAP 674
40 static int
41 dissect_acap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
43 bool is_request;
44 proto_tree *acap_tree, *reqresp_tree;
45 proto_item *ti, *hidden_item;
46 int offset = 0;
47 const unsigned char *line;
48 int next_offset;
49 int linelen;
50 int tokenlen;
51 const unsigned char *next_token;
55 * If this should be a request or response, do this quick check to see if
56 * it begins with a string...
57 * Otherwise, looking for the end of line in a binary file can take a long time
58 * and this probably isn't ACAP
60 if (!g_ascii_isprint(tvb_get_uint8(tvb, offset))) {
61 return 0;
64 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ACAP");
67 * Find the end of the first line.
69 * Note that "tvb_find_line_end()" will return a value that is
70 * not longer than what's in the buffer, so the "tvb_get_ptr()"
71 * call won't throw an exception.
73 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, false);
74 line = tvb_get_ptr(tvb, offset, linelen);
76 if (pinfo->match_uint == pinfo->destport)
77 is_request = true;
78 else
79 is_request = false;
82 * Put the first line from the buffer into the summary
83 * (but leave out the line terminator).
85 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
86 is_request ? "Request" : "Response",
87 format_text(pinfo->pool, line, linelen));
89 if (tree) {
90 ti = proto_tree_add_item(tree, proto_acap, tvb, offset, -1,
91 ENC_NA);
92 acap_tree = proto_item_add_subtree(ti, ett_acap);
94 if (is_request) {
95 hidden_item = proto_tree_add_boolean(acap_tree,
96 hf_acap_request, tvb, 0, 0, true);
97 proto_item_set_hidden(hidden_item);
98 } else {
99 hidden_item = proto_tree_add_boolean(acap_tree,
100 hf_acap_response, tvb, 0, 0, true);
101 proto_item_set_hidden(hidden_item);
105 * Put the line into the protocol tree.
107 ti = proto_tree_add_format_text(acap_tree, tvb, offset, next_offset - offset);
108 reqresp_tree = proto_item_add_subtree(ti, ett_acap_reqresp);
111 * Show the first line as tags + requests or replies.
115 * Extract the first token, and, if there is a first
116 * token, add it as the request or reply tag.
118 tokenlen = get_token_len(line, line + linelen, &next_token);
119 if (tokenlen != 0) {
120 if (is_request) {
121 proto_tree_add_string(reqresp_tree, hf_acap_request_tag, tvb, offset,
122 tokenlen, format_text(pinfo->pool, line, tokenlen));
123 } else {
124 proto_tree_add_string(reqresp_tree, hf_acap_response_tag, tvb, offset,
125 tokenlen, format_text(pinfo->pool, line, tokenlen));
127 offset += (int)(next_token - line);
128 linelen -= (int)(next_token - line);
129 line = next_token;
133 * Add the rest of the line as request or reply data.
135 if (linelen != 0) {
136 if (is_request) {
137 proto_tree_add_string(reqresp_tree, hf_acap_request_data, tvb, offset,
138 linelen, format_text(pinfo->pool, line, linelen));
139 } else {
140 proto_tree_add_string(reqresp_tree, hf_acap_response_data, tvb, offset,
141 linelen, format_text(pinfo->pool, line, linelen));
146 * XXX - show the rest of the frame; this requires that
147 * we handle literals, quoted strings, continuation
148 * responses, etc..
150 * This involves a state machine, and attaching
151 * state information to the packets.
154 return tvb_captured_length(tvb);
157 void
158 proto_register_acap(void)
160 static hf_register_info hf[] = {
161 { &hf_acap_response,
162 { "Response", "acap.response",
163 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
164 "true if ACAP response", HFILL }
166 { &hf_acap_request,
167 { "Request", "acap.request",
168 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
169 "true if ACAP request", HFILL }
171 { &hf_acap_request_tag,
172 { "Request Tag", "acap.request_tag",
173 FT_STRING, BASE_NONE, NULL, 0x0,
174 NULL, HFILL }
176 { &hf_acap_response_tag,
177 { "Response Tag", "acap.response_tag",
178 FT_STRING, BASE_NONE, NULL, 0x0,
179 NULL, HFILL }
181 { &hf_acap_request_data,
182 { "Request", "acap.request_data",
183 FT_STRING, BASE_NONE, NULL, 0x0,
184 NULL, HFILL }
186 { &hf_acap_response_data,
187 { "Response", "acap.response_data",
188 FT_STRING, BASE_NONE, NULL, 0x0,
189 NULL, HFILL }
193 static int *ett[] = {
194 &ett_acap,
195 &ett_acap_reqresp,
198 proto_acap = proto_register_protocol("Application Configuration Access Protocol",
199 "ACAP", "acap");
200 proto_register_field_array(proto_acap, hf, array_length(hf));
201 proto_register_subtree_array(ett, array_length(ett));
203 acap_handle = register_dissector("acap", dissect_acap, proto_acap);
206 void
207 proto_reg_handoff_acap(void)
209 dissector_add_uint_with_preference("tcp.port", TCP_PORT_ACAP, acap_handle);
213 * Editor modelines - https://www.wireshark.org/tools/modelines.html
215 * Local variables:
216 * c-basic-offset: 4
217 * tab-width: 8
218 * indent-tabs-mode: nil
219 * End:
221 * vi: set shiftwidth=4 tabstop=8 expandtab:
222 * :indentSize=4:tabSize=8:noTabs=true: