2 * Routines for ICAP packet disassembly
5 * Srishylam Simharajan simha@netapp.com
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
37 #include <epan/strutil.h>
39 typedef enum _icap_type {
47 static int proto_icap = -1;
48 static int hf_icap_response = -1;
49 static int hf_icap_reqmod = -1;
50 static int hf_icap_respmod = -1;
51 static int hf_icap_options = -1;
52 static int hf_icap_other = -1;
54 static gint ett_icap = -1;
56 static dissector_handle_t data_handle;
58 #define TCP_PORT_ICAP 1344
59 static int is_icap_message(const guchar *data, int linelen, icap_type_t *type);
61 dissect_icap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
63 proto_tree *icap_tree = NULL;
64 proto_item *ti = NULL;
65 proto_item *hidden_item;
69 const guchar *linep, *lineend;
72 icap_type_t icap_type;
75 if (check_col(pinfo->cinfo, COL_PROTOCOL))
76 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICAP");
78 if (check_col(pinfo->cinfo, COL_INFO)) {
80 * Put the first line from the buffer into the summary
81 * if it's an ICAP header (but leave out the
83 * Otherwise, just call it a continuation.
85 * Note that "tvb_find_line_end()" will return a value that
86 * is not longer than what's in the buffer, so the
87 * "tvb_get_ptr()" call won't throw an exception.
89 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
91 line = tvb_get_ptr(tvb, offset, linelen);
92 icap_type = ICAP_OTHER; /* type not known yet */
93 if (is_icap_message(line, linelen, &icap_type))
94 col_add_str(pinfo->cinfo, COL_INFO,
95 format_text(line, linelen));
97 col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
101 ti = proto_tree_add_item(tree, proto_icap, tvb, offset, -1,
103 icap_tree = proto_item_add_subtree(ti, ett_icap);
107 * Process the packet data, a line at a time.
109 icap_type = ICAP_OTHER; /* type not known yet */
110 while (tvb_offset_exists(tvb, offset)) {
111 gboolean is_icap = FALSE;
112 gboolean loop_done = FALSE;
114 * Find the end of the line.
116 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
120 * Get a buffer that refers to the line.
122 line = tvb_get_ptr(tvb, offset, linelen);
123 lineend = line + linelen;
128 if (is_icap_message(line, linelen, &icap_type)) {
134 * if it looks like a blank line, end of header perhaps?
142 * No. Does it look like a header?
146 while (linep < lineend && (!loop_done)) {
150 * This must be a CHAR to be part of a token; that
151 * means it must be ASCII.
155 break; /* not ASCII, thus not a CHAR */
159 * This mustn't be a CTL to be part of a token.
161 * XXX - what about leading LWS on continuation
166 break; /* CTL, not part of a header */
188 * It's a separator, so it's not part of a
189 * token, so it's not a field name for the
190 * beginning of a header.
192 * (We don't have to check for HT; that's
193 * already been ruled out by "iscntrl()".)
195 * XXX - what about ' '? HTTP's checks
204 * This ends the token; we consider this
213 * We don't consider this part of an ICAP message,
214 * so we don't display it.
215 * (Yeah, that means we don't display, say, a text/icap
216 * page, but you can get that from the data pane.)
222 proto_tree_add_text(icap_tree, tvb, offset,
223 next_offset - offset, "%s",
224 tvb_format_text(tvb, offset,
225 next_offset - offset)
228 offset = next_offset;
235 hidden_item = proto_tree_add_boolean(icap_tree,
236 hf_icap_options, tvb, 0, 0, 1);
237 PROTO_ITEM_SET_HIDDEN(hidden_item);
241 hidden_item = proto_tree_add_boolean(icap_tree,
242 hf_icap_reqmod, tvb, 0, 0, 1);
243 PROTO_ITEM_SET_HIDDEN(hidden_item);
247 hidden_item = proto_tree_add_boolean(icap_tree,
248 hf_icap_respmod, tvb, 0, 0, 1);
249 PROTO_ITEM_SET_HIDDEN(hidden_item);
253 hidden_item = proto_tree_add_boolean(icap_tree,
254 hf_icap_response, tvb, 0, 0, 1);
255 PROTO_ITEM_SET_HIDDEN(hidden_item);
264 datalen = tvb_length_remaining(tvb, offset);
266 call_dissector(data_handle,
267 tvb_new_subset(tvb, offset, -1, -1), pinfo, icap_tree);
273 is_icap_message(const guchar *data, int linelen, icap_type_t *type)
275 #define ICAP_COMPARE(string, length, msgtype) { \
276 if (strncmp(data, string, length) == 0) { \
277 if (*type == ICAP_OTHER) \
283 * From draft-elson-opes-icap-01(72).txt
286 ICAP_COMPARE("ICAP/", 5, ICAP_RESPONSE); /* response */
289 ICAP_COMPARE("REQMOD ", 7, ICAP_REQMOD); /* request mod */
292 ICAP_COMPARE("OPTIONS ", 8, ICAP_OPTIONS); /* options */
293 ICAP_COMPARE("RESPMOD ", 8, ICAP_RESPMOD); /* response mod */
300 proto_register_icap(void)
302 static hf_register_info hf[] = {
304 { "Response", "icap.response",
305 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
306 "TRUE if ICAP response", HFILL }},
308 { "Reqmod", "icap.reqmod",
309 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
310 "TRUE if ICAP reqmod", HFILL }},
312 { "Respmod", "icap.respmod",
313 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
314 "TRUE if ICAP respmod", HFILL }},
316 { "Options", "icap.options",
317 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
318 "TRUE if ICAP options", HFILL }},
320 { "Other", "icap.other",
321 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
322 "TRUE if ICAP other", HFILL }},
324 static gint *ett[] = {
328 proto_icap = proto_register_protocol(
329 "Internet Content Adaptation Protocol",
331 proto_register_field_array(proto_icap, hf, array_length(hf));
332 proto_register_subtree_array(ett, array_length(ett));
337 proto_reg_handoff_icap(void)
339 dissector_handle_t icap_handle;
341 data_handle = find_dissector("data");
342 icap_handle = create_dissector_handle(dissect_icap, proto_icap);
343 dissector_add("tcp.port", TCP_PORT_ICAP, icap_handle);