Replace the ETT_ "enum" members, declared in "packet.h", with
[obnox/wireshark/wip.git] / packet-sdp.c
1 /* packet-sdp.c
2  * Routines for SDP packet disassembly
3  *
4  * Jason Lango <jal@netapp.com>
5  * Liberally copied from packet-http.c, by Guy Harris <guy@netapp.com>
6  *
7  * $Id: packet-sdp.c,v 1.4 1999/11/16 11:42:53 guy Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@zing.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * 
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  * 
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  *
28  *
29  */
30
31 #include "config.h"
32
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
35 #endif
36
37 #include <string.h>
38 #include <ctype.h>
39
40 #include <glib.h>
41 #include "packet.h"
42
43 static int proto_sdp = -1;
44
45 static int ett_sdp = -1;
46
47 void dissect_sdp(const u_char *pd, int offset, frame_data *fd,
48         proto_tree *tree)
49 {
50         proto_tree      *sdp_tree;
51         proto_item      *ti;
52         const u_char    *data, *dataend;
53         const u_char    *lineend, *eol;
54         int             linelen;
55         u_char          section;
56         u_char          type;
57         const u_char    *value;
58         int             valuelen;
59         const char      *typename;
60
61         data = &pd[offset];
62         dataend = data + END_OF_FRAME;
63
64         if (check_col(fd, COL_PROTOCOL))
65                 col_add_str(fd, COL_PROTOCOL, "SDP");
66
67         if (check_col(fd, COL_INFO)) {
68                 /* XXX: Needs description. */
69                 col_add_str(fd, COL_INFO, "Session Description");
70         }
71
72         if (!tree)
73                 return;
74
75         ti = proto_tree_add_item(tree, proto_sdp, offset, END_OF_FRAME, NULL);
76         sdp_tree = proto_item_add_subtree(ti, ett_sdp);
77
78         section = 0;
79         for (; data < dataend; offset += linelen, data = lineend) {
80                 /*
81                  * Find the end of the line.
82                  */
83                 lineend = find_line_end(data, dataend, &eol);
84                 linelen = lineend - data;
85
86                 /*
87                  * Line must contain at least e.g. "v=".
88                  */
89                 if (linelen < 2)
90                         break;
91
92                 type = data[0];
93                 if (data[1] != '=') {
94                         proto_tree_add_text(sdp_tree, offset, linelen,
95                                 "Invalid line: %s",
96                                 format_text(data, linelen));
97                         continue;
98                 }
99                 value = data + 2;
100                 valuelen = linelen - 2;
101
102                 /*
103                  * Attributes.
104                  */
105                 switch (type) {
106                 case 'v':
107                         section = 'v';
108                         typename = "Session Description, version";
109                         break;
110                 case 'o':
111                         typename = "Owner/Creator, Session Id";
112                         break;
113                 case 's':
114                         typename = "Session Name";
115                         break;
116                 case 'i':
117                         if (section == 'v')
118                                 typename = "Session Information";
119                         else if (section == 'm')
120                                 typename = "Media Title";
121                         else
122                                 typename = "Misplaced";
123                         break;
124                 case 'u':
125                         typename = "URI of Description";
126                         break;
127                 case 'e':
128                         typename = "E-mail Address";
129                         break;
130                 case 'p':
131                         typename = "Phone Number";
132                         break;
133                 case 'c':
134                         typename = "Connection Information";
135                         break;
136                 case 'b':
137                         typename = "Bandwidth Information";
138                         break;
139                 case 't':
140                         section = 't';
141                         typename = "Time Description, active time";
142                         break;
143                 case 'r':
144                         typename = "Repeat Time";
145                         break;
146                 case 'm':
147                         section = 'm';
148                         typename = "Media Description, name and address";
149                         break;
150                 case 'k':
151                         typename = "Encryption Key";
152                         break;
153                 case 'a':
154                         if (section == 'v')
155                                 typename = "Session Attribute";
156                         else if (section == 'm')
157                                 typename = "Media Attribute";
158                         else
159                                 typename = "Misplaced";
160                         break;
161                 case 'z':
162                         typename = "Time Zone Adjustment";
163                         break;
164                 default:
165                         typename = "Unknown";
166                         break;
167                 }
168
169                 proto_tree_add_text(sdp_tree, offset, linelen,
170                         "%s (%c): %s", typename, type,
171                         format_text(value, valuelen));
172         }
173
174         if (data < dataend) {
175                 proto_tree_add_text(sdp_tree, offset, END_OF_FRAME,
176                     "Data (%d bytes)", END_OF_FRAME);
177         }
178 }
179
180 void
181 proto_register_sdp(void)
182 {
183 /*        static hf_register_info hf[] = {
184                 { &variable,
185                 { "Name",           "sdp.abbreviation", TYPE, VALS_POINTER }},
186         };*/
187         static gint *ett[] = {
188                 &ett_sdp,
189         };
190
191         proto_sdp = proto_register_protocol("Session Description Protocol", "sdp");
192  /*       proto_register_field_array(proto_sdp, hf, array_length(hf));*/
193         proto_register_subtree_array(ett, array_length(ett));
194 }