Move 3 ASN1 dissectors to 'clean' group; move 1 PIDL dissector to 'dirty' group.
[metze/wireshark/wip.git] / epan / dissectors / packet-sipfrag.c
1 /* Routines for sipfrag packet disassembly (RFC 3420)
2  *
3  * Martin Mathieson
4  * Based on packet-sdp.c
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 #include "config.h"
28
29 #include <epan/packet.h>
30
31 /*
32  * Doesn't do a detailed dissection of the lines of the message, just treat as text.
33  */
34
35
36 /* Initialize the protocol and registered fields. */
37 static int proto_sipfrag = -1;
38 static int hf_sipfrag_line = -1;
39
40 /* Protocol subtree. */
41 static int ett_sipfrag = -1;
42
43 void proto_reg_handoff_sipfrag(void);
44 static void dissect_sipfrag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
45
46
47 /* Main dissection function. */
48 static void dissect_sipfrag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
49 {
50     proto_tree  *sipfrag_tree;
51     proto_item  *ti;
52     gint        offset = 0;
53     gint        next_offset;
54     int         linelen;
55     char        *string;
56     gint        lines = 0;
57
58     /* Append this protocol name rather than replace. */
59     col_append_str(pinfo->cinfo, COL_PROTOCOL, "/sipfrag");
60
61     /* Add mention of this protocol to info column */
62     col_append_str(pinfo->cinfo, COL_INFO, ", with Sipfrag");
63
64     /* Create sipfrag tree. */
65     ti = proto_tree_add_item(tree, proto_sipfrag, tvb, offset, -1, ENC_NA);
66     sipfrag_tree = proto_item_add_subtree(ti, ett_sipfrag);
67
68     /* Show the sipfrag message a line at a time. */
69     while (tvb_reported_length_remaining(tvb, offset) > 0)
70     {
71         /* Find the end of the line. */
72         linelen = tvb_find_line_end_unquoted(tvb, offset, -1, &next_offset);
73
74         /* For now, add all lines as unparsed strings */
75
76         /* Extract & add the string. */
77         string = (char*)tvb_get_ephemeral_string(tvb, offset, linelen);
78         proto_tree_add_string_format(sipfrag_tree, hf_sipfrag_line,
79                                      tvb, offset,
80                                      linelen, string,
81                                      "%s", string);
82         lines++;
83
84         /* Show first line in info column */
85         if (lines == 1) {
86             col_append_fstr(pinfo->cinfo, COL_INFO, "(%s", string);
87         }
88
89         /* Move onto next line. */
90         offset = next_offset;
91     }
92
93     /* Close off summary of sipfrag in info column */
94     col_append_str(pinfo->cinfo, COL_INFO, (lines > 1) ? "...)" : ")");
95 }
96
97 void proto_register_sipfrag(void)
98 {
99     static hf_register_info hf[] =
100     {
101         { &hf_sipfrag_line,
102             { "Line",
103               "sipfrag.line",FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL
104             }
105         },
106     };
107
108     static gint *ett[] =
109     {
110         &ett_sipfrag
111     };
112
113     /* Register protocol. */
114     proto_sipfrag = proto_register_protocol("Sipfrag", "SIPFRAG", "sipfrag");
115     proto_register_field_array(proto_sipfrag, hf, array_length(hf));
116     proto_register_subtree_array(ett, array_length(ett));
117
118     /* Allow other dissectors to find this one by name. */
119     register_dissector("sipfrag", dissect_sipfrag, proto_sipfrag);
120 }
121
122 void proto_reg_handoff_sipfrag(void)
123 {
124     dissector_handle_t sipfrag_handle = find_dissector("sipfrag");
125     dissector_add_string("media_type", "message/sipfrag", sipfrag_handle);
126 }
127
128