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 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICAP");
77 if (check_col(pinfo->cinfo, COL_INFO)) {
79 * Put the first line from the buffer into the summary
80 * if it's an ICAP header (but leave out the
82 * Otherwise, just call it a continuation.
84 * Note that "tvb_find_line_end()" will return a value that
85 * is not longer than what's in the buffer, so the
86 * "tvb_get_ptr()" call won't throw an exception.
88 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
90 line = tvb_get_ptr(tvb, offset, linelen);
91 icap_type = ICAP_OTHER; /* type not known yet */
92 if (is_icap_message(line, linelen, &icap_type))
93 col_add_str(pinfo->cinfo, COL_INFO,
94 format_text(line, linelen));
96 col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
100 ti = proto_tree_add_item(tree, proto_icap, tvb, offset, -1,
102 icap_tree = proto_item_add_subtree(ti, ett_icap);
106 * Process the packet data, a line at a time.
108 icap_type = ICAP_OTHER; /* type not known yet */
109 while (tvb_offset_exists(tvb, offset)) {
110 gboolean is_icap = FALSE;
111 gboolean loop_done = FALSE;
113 * Find the end of the line.
115 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
119 * Get a buffer that refers to the line.
121 line = tvb_get_ptr(tvb, offset, linelen);
122 lineend = line + linelen;
127 if (is_icap_message(line, linelen, &icap_type)) {
133 * if it looks like a blank line, end of header perhaps?
141 * No. Does it look like a header?
145 while (linep < lineend && (!loop_done)) {
149 * This must be a CHAR to be part of a token; that
150 * means it must be ASCII.
154 break; /* not ASCII, thus not a CHAR */
158 * This mustn't be a CTL to be part of a token.
160 * XXX - what about leading LWS on continuation
165 break; /* CTL, not part of a header */
187 * It's a separator, so it's not part of a
188 * token, so it's not a field name for the
189 * beginning of a header.
191 * (We don't have to check for HT; that's
192 * already been ruled out by "iscntrl()".)
194 * XXX - what about ' '? HTTP's checks
203 * This ends the token; we consider this
212 * We don't consider this part of an ICAP message,
213 * so we don't display it.
214 * (Yeah, that means we don't display, say, a text/icap
215 * page, but you can get that from the data pane.)
221 proto_tree_add_text(icap_tree, tvb, offset,
222 next_offset - offset, "%s",
223 tvb_format_text(tvb, offset,
224 next_offset - offset)
227 offset = next_offset;
234 hidden_item = proto_tree_add_boolean(icap_tree,
235 hf_icap_options, tvb, 0, 0, 1);
236 PROTO_ITEM_SET_HIDDEN(hidden_item);
240 hidden_item = proto_tree_add_boolean(icap_tree,
241 hf_icap_reqmod, tvb, 0, 0, 1);
242 PROTO_ITEM_SET_HIDDEN(hidden_item);
246 hidden_item = proto_tree_add_boolean(icap_tree,
247 hf_icap_respmod, tvb, 0, 0, 1);
248 PROTO_ITEM_SET_HIDDEN(hidden_item);
252 hidden_item = proto_tree_add_boolean(icap_tree,
253 hf_icap_response, tvb, 0, 0, 1);
254 PROTO_ITEM_SET_HIDDEN(hidden_item);
263 datalen = tvb_length_remaining(tvb, offset);
265 call_dissector(data_handle,
266 tvb_new_subset(tvb, offset, -1, -1), pinfo, icap_tree);
272 is_icap_message(const guchar *data, int linelen, icap_type_t *type)
274 #define ICAP_COMPARE(string, length, msgtype) { \
275 if (strncmp(data, string, length) == 0) { \
276 if (*type == ICAP_OTHER) \
282 * From draft-elson-opes-icap-01(72).txt
285 ICAP_COMPARE("ICAP/", 5, ICAP_RESPONSE); /* response */
288 ICAP_COMPARE("REQMOD ", 7, ICAP_REQMOD); /* request mod */
291 ICAP_COMPARE("OPTIONS ", 8, ICAP_OPTIONS); /* options */
292 ICAP_COMPARE("RESPMOD ", 8, ICAP_RESPMOD); /* response mod */
299 proto_register_icap(void)
301 static hf_register_info hf[] = {
303 { "Response", "icap.response",
304 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
305 "TRUE if ICAP response", HFILL }},
307 { "Reqmod", "icap.reqmod",
308 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
309 "TRUE if ICAP reqmod", HFILL }},
311 { "Respmod", "icap.respmod",
312 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
313 "TRUE if ICAP respmod", HFILL }},
315 { "Options", "icap.options",
316 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
317 "TRUE if ICAP options", HFILL }},
319 { "Other", "icap.other",
320 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
321 "TRUE if ICAP other", HFILL }},
323 static gint *ett[] = {
327 proto_icap = proto_register_protocol(
328 "Internet Content Adaptation Protocol",
330 proto_register_field_array(proto_icap, hf, array_length(hf));
331 proto_register_subtree_array(ett, array_length(ett));
336 proto_reg_handoff_icap(void)
338 dissector_handle_t icap_handle;
340 data_handle = find_dissector("data");
341 icap_handle = create_dissector_handle(dissect_icap, proto_icap);
342 dissector_add("tcp.port", TCP_PORT_ICAP, icap_handle);