"const"ifty some function arguments and structure members, and "#if 0"
[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.2 1999/07/07 22:51:53 gram 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 void dissect_sdp(const u_char *pd, int offset, frame_data *fd,
44         proto_tree *tree)
45 {
46         proto_tree      *sdp_tree;
47         proto_item      *ti;
48         const u_char    *data, *dataend;
49         const u_char    *lineend, *eol;
50         int             linelen;
51         u_char          section;
52         u_char          type;
53         const u_char    *value;
54         int             valuelen;
55         const char      *typename;
56
57         data = &pd[offset];
58         dataend = data + END_OF_FRAME;
59
60         if (check_col(fd, COL_PROTOCOL))
61                 col_add_str(fd, COL_PROTOCOL, "SDP");
62
63         if (check_col(fd, COL_INFO)) {
64                 /* XXX: Needs description. */
65                 col_add_str(fd, COL_INFO, "Session Description");
66         }
67
68         if (!tree)
69                 return;
70
71         ti = proto_tree_add_text(tree, offset, END_OF_FRAME,
72                 "Session Description Protocol");
73         sdp_tree = proto_item_add_subtree(ti, ETT_SDP);
74
75         section = 0;
76         for (; data < dataend; offset += linelen, data = lineend) {
77                 /*
78                  * Find the end of the line.
79                  */
80                 lineend = find_line_end(data, dataend, &eol);
81                 linelen = lineend - data;
82
83                 /*
84                  * Line must contain at least e.g. "v=".
85                  */
86                 if (linelen < 2)
87                         break;
88
89                 type = data[0];
90                 if (data[1] != '=') {
91                         proto_tree_add_text(sdp_tree, offset, linelen,
92                                 "Invalid line: %s",
93                                 format_text(data, linelen));
94                         continue;
95                 }
96                 value = data + 2;
97                 valuelen = linelen - 2;
98
99                 /*
100                  * Attributes.
101                  */
102                 switch (type) {
103                 case 'v':
104                         section = 'v';
105                         typename = "Session Description, version";
106                         break;
107                 case 'o':
108                         typename = "Owner/Creator, Session Id";
109                         break;
110                 case 's':
111                         typename = "Session Name";
112                         break;
113                 case 'i':
114                         if (section == 'v')
115                                 typename = "Session Information";
116                         else if (section == 'm')
117                                 typename = "Media Title";
118                         else
119                                 typename = "Misplaced";
120                         break;
121                 case 'u':
122                         typename = "URI of Description";
123                         break;
124                 case 'e':
125                         typename = "E-mail Address";
126                         break;
127                 case 'p':
128                         typename = "Phone Number";
129                         break;
130                 case 'c':
131                         typename = "Connection Information";
132                         break;
133                 case 'b':
134                         typename = "Bandwidth Information";
135                         break;
136                 case 't':
137                         section = 't';
138                         typename = "Time Description, active time";
139                         break;
140                 case 'r':
141                         typename = "Repeat Time";
142                         break;
143                 case 'm':
144                         section = 'm';
145                         typename = "Media Description, name and address";
146                         break;
147                 case 'k':
148                         typename = "Encryption Key";
149                         break;
150                 case 'a':
151                         if (section == 'v')
152                                 typename = "Session Attribute";
153                         else if (section == 'm')
154                                 typename = "Media Attribute";
155                         else
156                                 typename = "Misplaced";
157                         break;
158                 case 'z':
159                         typename = "Time Zone Adjustment";
160                         break;
161                 default:
162                         typename = "Unknown";
163                         break;
164                 }
165
166                 proto_tree_add_text(sdp_tree, offset, linelen,
167                         "%s (%c): %s", typename, type,
168                         format_text(value, valuelen));
169         }
170
171         if (data < dataend) {
172                 proto_tree_add_text(sdp_tree, offset, END_OF_FRAME,
173                     "Data (%d bytes)", END_OF_FRAME);
174         }
175 }