Make the message popped up if you try to do a capture on a Win32 machine
[obnox/wireshark/wip.git] / packet-sdp.c
index edb6a127df71be4ba35cb539e2c2ae25c16c0f4e..b76019c05b54bcb38073941ed77a4e8c2e88f0b1 100644 (file)
@@ -4,7 +4,7 @@
  * Jason Lango <jal@netapp.com>
  * Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
  *
- * $Id: packet-sdp.c,v 1.10 2000/09/11 16:16:03 gram Exp $
+ * $Id: packet-sdp.c,v 1.20 2001/01/25 06:14:14 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -45,46 +45,61 @@ static int proto_sdp = -1;
 
 static int ett_sdp = -1;
 
-void dissect_sdp(const u_char *pd, int offset, frame_data *fd,
-       proto_tree *tree)
+static void
+dissect_sdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
        proto_tree      *sdp_tree;
        proto_item      *ti;
-       const u_char    *data, *dataend;
-       const u_char    *lineend, *eol;
+       gint            offset = 0;
+       const u_char    *line;
+       gint            next_offset;
        int             linelen;
        u_char          section;
        u_char          type;
        const u_char    *value;
        int             valuelen;
        const char      *typename;
-
-       OLD_CHECK_DISPLAY_AS_DATA(proto_sdp, pd, offset, fd, tree);
-
-       data = &pd[offset];
-       dataend = data + END_OF_FRAME;
-
-       if (check_col(fd, COL_PROTOCOL))
-               col_add_str(fd, COL_PROTOCOL, "SDP");
-
-       if (check_col(fd, COL_INFO)) {
+       int             datalen;
+
+       /*
+        * As RFC 2327 says, "SDP is purely a format for session
+        * description - it does not incorporate a transport protocol,
+        * and is intended to use different transport protocols as
+        * appropriate including the Session Announcement Protocol,
+        * Session Initiation Protocol, Real-Time Streaming Protocol,
+        * electronic mail using the MIME extensions, and the
+        * Hypertext Transport Protocol."
+        *
+        * We therefore don't set the protocol or info columns;
+        * instead, we append to them, so that we don't erase
+        * what the protocol inside which the SDP stuff resides
+        * put there.
+        */
+       if (check_col(pinfo->fd, COL_PROTOCOL))
+               col_append_str(pinfo->fd, COL_PROTOCOL, "/SDP");
+
+       if (check_col(pinfo->fd, COL_INFO)) {
                /* XXX: Needs description. */
-               col_add_str(fd, COL_INFO, "Session Description");
+               col_append_str(pinfo->fd, COL_INFO, ", with session description");
        }
 
        if (!tree)
                return;
 
-       ti = proto_tree_add_item(tree, proto_sdp, NullTVB, offset, END_OF_FRAME, FALSE);
+       ti = proto_tree_add_item(tree, proto_sdp, tvb, offset,
+           tvb_length_remaining(tvb, offset), FALSE);
        sdp_tree = proto_item_add_subtree(ti, ett_sdp);
 
+       /*
+        * Show the SDP message a line at a time.
+        */
        section = 0;
-       for (; data < dataend; offset += linelen, data = lineend) {
+       while (tvb_offset_exists(tvb, offset)) {
                /*
                 * Find the end of the line.
                 */
-               lineend = find_line_end(data, dataend, &eol);
-               linelen = lineend - data;
+               linelen = tvb_find_line_end_unquoted(tvb, offset, -1,
+                   &next_offset);
 
                /*
                 * Line must contain at least e.g. "v=".
@@ -92,14 +107,17 @@ void dissect_sdp(const u_char *pd, int offset, frame_data *fd,
                if (linelen < 2)
                        break;
 
-               type = data[0];
-               if (data[1] != '=') {
-                       proto_tree_add_text(sdp_tree, NullTVB, offset, linelen,
-                               "Invalid line: %s",
-                               format_text(data, linelen));
+               line = tvb_get_ptr(tvb, offset, next_offset - offset);
+               type = line[0];
+               if (line[1] != '=') {
+                       proto_tree_add_text(sdp_tree, tvb, offset,
+                           next_offset - offset,
+                           "Invalid line: %s",
+                           tvb_format_text(tvb, offset, next_offset - offset));
+                        offset = next_offset;
                        continue;
                }
-               value = data + 2;
+               value = line + 2;
                valuelen = linelen - 2;
 
                /*
@@ -169,14 +187,17 @@ void dissect_sdp(const u_char *pd, int offset, frame_data *fd,
                        break;
                }
 
-               proto_tree_add_text(sdp_tree, NullTVB, offset, linelen,
-                       "%s (%c): %s", typename, type,
-                       format_text(value, valuelen));
+               proto_tree_add_text(sdp_tree, tvb, offset,
+                   next_offset - offset,
+                   "%s (%c): %s", typename, type,
+                   format_text(value, valuelen));
+               offset = next_offset;
        }
 
-       if (data < dataend) {
-               proto_tree_add_text(sdp_tree, NullTVB, offset, END_OF_FRAME,
-                   "Data (%d bytes)", END_OF_FRAME);
+       datalen = tvb_length_remaining(tvb, offset);
+       if (datalen > 0) {
+               proto_tree_add_text(sdp_tree, tvb, offset, datalen,
+                   "Data (%d bytes)", datalen);
        }
 }
 
@@ -191,7 +212,16 @@ proto_register_sdp(void)
                &ett_sdp,
        };
 
-        proto_sdp = proto_register_protocol("Session Description Protocol", "sdp");
+        proto_sdp = proto_register_protocol("Session Description Protocol",
+           "SDP", "sdp");
  /*       proto_register_field_array(proto_sdp, hf, array_length(hf));*/
        proto_register_subtree_array(ett, array_length(ett));
+
+       /*
+        * Register the dissector by name, so other dissectors can
+        * grab it by name rather than just referring to it directly
+        * (you can't refer to it directly from a plugin dissector
+        * on Windows without stuffing it into the Big Transfer Vector).
+        */
+       register_dissector("sdp", dissect_sdp, proto_sdp);
 }