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