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