2 * Routines for ACAP packet dissection
3 * Copyright 2003, Brad Hards <bradh@frogmouth.net>
4 * Heavily based in packet-imap.c, Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * Copied from packet-imap.c
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #define NEW_PROTO_TREE_API
34 #include <epan/packet.h>
35 #include <epan/strutil.h>
37 /* Forward declarations */
38 void proto_register_acap(void);
39 void proto_reg_handoff_acap(void);
41 static dissector_handle_t acap_handle
;
43 static header_field_info
*hfi_acap
= NULL
;
45 #define HFI_ACAP HFI_INIT(proto_acap)
47 static header_field_info hfi_acap_response HFI_ACAP
=
48 { "Response", "acap.response",
49 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
50 "TRUE if ACAP response", HFILL
};
52 static header_field_info hfi_acap_request HFI_ACAP
=
53 { "Request", "acap.request",
54 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
55 "TRUE if ACAP request", HFILL
};
58 static gint ett_acap
= -1;
59 static gint ett_acap_reqresp
= -1;
61 #define TCP_PORT_ACAP 674
64 dissect_acap(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
67 proto_tree
*acap_tree
, *reqresp_tree
;
68 proto_item
*ti
, *hidden_item
;
74 const guchar
*next_token
;
76 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ACAP");
79 * Find the end of the first line.
81 * Note that "tvb_find_line_end()" will return a value that is
82 * not longer than what's in the buffer, so the "tvb_get_ptr()"
83 * call won't throw an exception.
85 linelen
= tvb_find_line_end(tvb
, offset
, -1, &next_offset
, FALSE
);
86 line
= tvb_get_ptr(tvb
, offset
, linelen
);
88 if (pinfo
->match_uint
== pinfo
->destport
)
94 * Put the first line from the buffer into the summary
95 * (but leave out the line terminator).
97 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s: %s",
98 is_request
? "Request" : "Response",
99 format_text(line
, linelen
));
102 ti
= proto_tree_add_item(tree
, hfi_acap
, tvb
, offset
, -1,
104 acap_tree
= proto_item_add_subtree(ti
, ett_acap
);
107 hidden_item
= proto_tree_add_boolean(acap_tree
,
108 &hfi_acap_request
, tvb
, 0, 0, TRUE
);
109 PROTO_ITEM_SET_HIDDEN(hidden_item
);
111 hidden_item
= proto_tree_add_boolean(acap_tree
,
112 &hfi_acap_response
, tvb
, 0, 0, TRUE
);
113 PROTO_ITEM_SET_HIDDEN(hidden_item
);
117 * Put the line into the protocol tree.
119 ti
= proto_tree_add_text(acap_tree
, tvb
, offset
,
120 next_offset
- offset
, "%s",
121 tvb_format_text(tvb
, offset
, next_offset
- offset
));
122 reqresp_tree
= proto_item_add_subtree(ti
, ett_acap_reqresp
);
125 * Show the first line as tags + requests or replies.
129 * Extract the first token, and, if there is a first
130 * token, add it as the request or reply tag.
132 tokenlen
= get_token_len(line
, line
+ linelen
, &next_token
);
135 proto_tree_add_text(reqresp_tree
, tvb
, offset
,
136 tokenlen
, "Request Tag: %s",
137 format_text(line
, tokenlen
));
139 proto_tree_add_text(reqresp_tree
, tvb
, offset
,
140 tokenlen
, "Response Tag: %s",
141 format_text(line
, tokenlen
));
143 offset
+= (int)(next_token
- line
);
144 linelen
-= (int)(next_token
- line
);
149 * Add the rest of the line as request or reply data.
153 proto_tree_add_text(reqresp_tree
, tvb
, offset
,
154 linelen
, "Request: %s",
155 format_text(line
, linelen
));
157 proto_tree_add_text(reqresp_tree
, tvb
, offset
,
158 linelen
, "Response: %s",
159 format_text(line
, linelen
));
164 * XXX - show the rest of the frame; this requires that
165 * we handle literals, quoted strings, continuation
168 * This involves a state machine, and attaching
169 * state information to the packets.
175 proto_register_acap(void)
177 #ifndef HAVE_HFI_SECTION_INIT
178 static header_field_info
*hfi
[] = {
184 static gint
*ett
[] = {
191 proto_acap
= proto_register_protocol("Application Configuration Access Protocol",
193 hfi_acap
= proto_registrar_get_nth(proto_acap
);
195 proto_register_fields(proto_acap
, hfi
, array_length(hfi
));
196 proto_register_subtree_array(ett
, array_length(ett
));
198 acap_handle
= create_dissector_handle(dissect_acap
, proto_acap
);
202 proto_reg_handoff_acap(void)
204 dissector_add_uint("tcp.port", TCP_PORT_ACAP
, acap_handle
);