Fix some aclocal warnings during autogen.sh
[obnox/wireshark/wip.git] / packet-sipfrag.c
1 /* Routines for sipfrag packet disassembly (RFC 3420)
2  *
3  * Martin Mathieson
4  * Based on packet-sdp.c
5  *
6  * $Id: packet-sipfrag.c,v 1.1 2004/02/03 18:57:26 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <epan/packet.h>
32
33 /*
34  * TODO:
35  * Doesn't currently dissect the lines of the message.
36  * Need to refactor SIP dissector and make its functionality available here
37  */
38
39
40 /* Initialize the protocol and registered fields. */
41 static int proto_sipfrag = -1;
42 static int hf_line = -1;
43
44 /* Protocol subtree. */
45 static int ett_sipfrag = -1;
46
47
48 /* Main dissection function. */
49 static void
50 dissect_sipfrag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
51 {
52     proto_tree  *sipfrag_tree;
53     proto_item  *ti;
54     gint        offset = 0;
55     gint        next_offset;
56     int         linelen;
57     char        *string;
58     gint        lines = 0;
59
60     /* Append this protocol name rather than replace. */
61     if (check_col(pinfo->cinfo, COL_PROTOCOL))
62         col_append_str(pinfo->cinfo, COL_PROTOCOL, "/sipfrag");
63
64     /* Add mention of this protocol to info column */
65     if (check_col(pinfo->cinfo, COL_INFO)) {
66         col_append_str(pinfo->cinfo, COL_INFO, ", with Sipfrag");
67     }
68
69     /* Create sipfrag tree. */
70     ti = proto_tree_add_item(tree, proto_sipfrag, tvb, offset, -1, FALSE);
71     sipfrag_tree = proto_item_add_subtree(ti, ett_sipfrag);
72
73     /* Show the sipfrag message a line at a time. */
74     while (tvb_reported_length_remaining(tvb, offset) > 0)
75     {
76         /* Find the end of the line. */
77         linelen = tvb_find_line_end_unquoted(tvb, offset, -1, &next_offset);
78
79         /* For now, add all lines as unparsed strings */
80
81         /* Extract & add the string. */
82         string = tvb_get_string(tvb, offset, linelen);
83         proto_tree_add_string_format(sipfrag_tree, hf_line,
84                                      tvb, offset,
85                                      linelen, string,
86                                      "%s", string);
87         lines++;
88
89         /* Show first line in info column */
90         if (lines == 1 && check_col(pinfo->cinfo, COL_INFO)) {
91             col_append_fstr(pinfo->cinfo, COL_INFO, "(%s", string);
92         }
93
94         /* Finished with this string now. */
95         g_free(string);
96
97         /* Move onto next line. */
98         offset = next_offset;
99     }
100
101     /* Close off summary of sipfrag in info column */
102     if (check_col(pinfo->cinfo, COL_INFO)) {
103         col_append_str(pinfo->cinfo, COL_INFO, (lines > 1) ? "...)" : ")");
104     }
105 }
106
107 void
108 proto_register_sipfrag(void)
109 {
110     static hf_register_info hf[] =
111     {
112         { &hf_line,
113             { "Line",
114               "sipfrag.line",FT_STRING, BASE_NONE, NULL, 0x0, "Line", HFILL
115             }
116         },
117     };
118
119     static gint *ett[] =
120     {
121         &ett_sipfrag
122     };
123
124     /* Register protocol. */
125     proto_sipfrag = proto_register_protocol("Sipfrag", "SIPFRAG", "sipfrag");
126     proto_register_field_array(proto_sipfrag, hf, array_length(hf));
127     proto_register_subtree_array(ett, array_length(ett));
128
129     /* Allow other dissectors to find this one by name. */
130     register_dissector("sipfrag", dissect_sipfrag, proto_sipfrag);
131 }
132
133 void
134 proto_reg_handoff_sipfrag(void)
135 {
136     dissector_handle_t sipfrag_handle = find_dissector("sipfrag");
137     dissector_add_string("media_type", "message/sipfrag", sipfrag_handle);
138 }
139
140