Remove forgotten useless lines
[metze/wireshark/wip.git] / epan / dissectors / packet-rtsp.c
1 /* packet-rtsp.c
2  * Routines for RTSP packet disassembly (RFC 2326)
3  *
4  * Jason Lango <jal@netapp.com>
5  * Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  *
27  * References:
28  * RTSP is defined in RFC 2326, http://www.ietf.org/rfc/rfc2326.txt?number=2326
29  * http://www.iana.org/assignments/rsvp-parameters
30  */
31
32 #include "config.h"
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <ctype.h>
37
38 #include <epan/prefs.h>
39
40 #include <glib.h>
41
42 #include <wsutil/str_util.h>
43
44 #include <epan/packet.h>
45 #include <epan/req_resp_hdrs.h>
46 #include "packet-rtp.h"
47 #include "packet-rtcp.h"
48 #include "packet-rdt.h"
49 #include <epan/conversation.h>
50 #include <epan/strutil.h>
51 #include "packet-e164.h"
52 #include <epan/emem.h>
53 #include <epan/tap.h>
54 #include <epan/tap-voip.h>
55
56 static int proto_rtsp           = -1;
57
58 static gint ett_rtsp            = -1;
59 static gint ett_rtspframe       = -1;
60 static gint ett_rtsp_method     = -1;
61
62 static int hf_rtsp_request      = -1;
63 static int hf_rtsp_response     = -1;
64 static int hf_rtsp_content_type = -1;
65 static int hf_rtsp_content_length       = -1;
66 static int hf_rtsp_method       = -1;
67 static int hf_rtsp_url          = -1;
68 static int hf_rtsp_status       = -1;
69 static int hf_rtsp_session      = -1;
70 static int hf_rtsp_transport    = -1;
71 static int hf_rtsp_rdtfeaturelevel      = -1;
72 static int hf_rtsp_X_Vig_Msisdn = -1;
73
74 static int voip_tap = -1;
75
76 static dissector_handle_t rtp_handle;
77 static dissector_handle_t rtcp_handle;
78 static dissector_handle_t rdt_handle;
79 static dissector_table_t media_type_dissector_table;
80
81 void proto_reg_handoff_rtsp(void);
82
83 /*
84  * desegmentation of RTSP headers
85  * (when we are over TCP or another protocol providing the desegmentation API)
86  */
87 static gboolean rtsp_desegment_headers = TRUE;
88
89 /*
90  * desegmentation of RTSP bodies
91  * (when we are over TCP or another protocol providing the desegmentation API)
92  * TODO let the user filter on content-type the bodies he wants desegmented
93  */
94 static gboolean rtsp_desegment_body = TRUE;
95
96 /* http://www.iana.org/assignments/port-numberslists two rtsp ports */
97 #define TCP_PORT_RTSP                   554
98 #define TCP_ALTERNATE_PORT_RTSP         8554
99 static guint global_rtsp_tcp_port = TCP_PORT_RTSP;
100 static guint global_rtsp_tcp_alternate_port = TCP_ALTERNATE_PORT_RTSP;
101 /*
102  * Takes an array of bytes, assumed to contain a null-terminated
103  * string, as an argument, and returns the length of the string -
104  * i.e., the size of the array, minus 1 for the null terminator.
105  */
106 #define STRLEN_CONST(str)       (sizeof (str) - 1)
107
108 #define RTSP_FRAMEHDR   ('$')
109
110 typedef struct {
111         dissector_handle_t              dissector;
112 } rtsp_interleaved_t;
113
114 #define RTSP_MAX_INTERLEAVED            (256)
115
116 /*
117  * Careful about dynamically allocating memory in this structure (say
118  * for dynamically increasing the size of the 'interleaved' array) -
119  * the containing structure is garbage collected and contained
120  * pointers will not be freed.
121  */
122 typedef struct {
123         rtsp_interleaved_t              interleaved[RTSP_MAX_INTERLEAVED];
124 } rtsp_conversation_data_t;
125
126 static int
127 dissect_rtspinterleaved(tvbuff_t *tvb, int offset, packet_info *pinfo,
128         proto_tree *tree)
129 {
130         guint           length_remaining;
131         proto_item      *ti;
132         proto_tree      *rtspframe_tree = NULL;
133         int             orig_offset;
134         guint8          rf_start;               /* always RTSP_FRAMEHDR */
135         guint8          rf_chan;        /* interleaved channel id */
136         guint16         rf_len;         /* packet length */
137         tvbuff_t        *next_tvb;
138         conversation_t  *conv;
139         rtsp_conversation_data_t        *data;
140         dissector_handle_t              dissector;
141
142         /*
143          * This will throw an exception if we don't have any data left.
144          * That's what we want.  (See "tcp_dissect_pdus()", which is
145          * similar.)
146          */
147         length_remaining = tvb_ensure_length_remaining(tvb, offset);
148
149         /*
150          * Can we do reassembly?
151          */
152         if (rtsp_desegment_headers && pinfo->can_desegment) {
153                 /*
154                  * Yes - would an RTSP multiplexed header starting at
155                  * this offset be split across segment boundaries?
156                  */
157                 if (length_remaining < 4) {
158                         /*
159                          * Yes.  Tell the TCP dissector where the data
160                          * for this message starts in the data it handed
161                          * us, and how many more bytes we need, and return.
162                          */
163                         pinfo->desegment_offset = offset;
164                         pinfo->desegment_len = 4 - length_remaining;
165                         return -1;
166                 }
167         }
168
169         /*
170          * Get the "$", channel, and length from the header.
171          */
172         orig_offset = offset;
173         rf_start = tvb_get_guint8(tvb, offset);
174         rf_chan = tvb_get_guint8(tvb, offset+1);
175         rf_len = tvb_get_ntohs(tvb, offset+2);
176
177         /*
178          * Can we do reassembly?
179          */
180         if (rtsp_desegment_body && pinfo->can_desegment) {
181                 /*
182                  * Yes - is the header + encapsulated packet split
183                  * across segment boundaries?
184                  */
185                 if (length_remaining < 4U + rf_len) {
186                         /*
187                          * Yes.  Tell the TCP dissector where the data
188                          * for this message starts in the data it handed
189                          * us, and how many more bytes we need, and return.
190                          */
191                         pinfo->desegment_offset = offset;
192                         pinfo->desegment_len = 4U + rf_len - length_remaining;
193                         return -1;
194                 }
195         }
196
197         if (check_col(pinfo->cinfo, COL_INFO))
198                 col_add_fstr(pinfo->cinfo, COL_INFO,
199                         "Interleaved channel 0x%02x, %u bytes",
200                         rf_chan, rf_len);
201
202         if (tree != NULL) {
203                 ti = proto_tree_add_protocol_format(tree, proto_rtsp, tvb,
204                     offset, 4,
205                     "RTSP Interleaved Frame, Channel: 0x%02x, %u bytes",
206                     rf_chan, rf_len);
207                 rtspframe_tree = proto_item_add_subtree(ti, ett_rtspframe);
208
209                 proto_tree_add_text(rtspframe_tree, tvb, offset, 1,
210                     "Magic: 0x%02x",
211                     rf_start);
212         }
213         offset += 1;
214
215         if (tree != NULL) {
216                 proto_tree_add_text(rtspframe_tree, tvb, offset, 1,
217                     "Channel: 0x%02x",
218                     rf_chan);
219         }
220         offset += 1;
221
222         if (tree != NULL) {
223                 proto_tree_add_text(rtspframe_tree, tvb, offset, 2,
224                     "Length: %u bytes",
225                     rf_len);
226         }
227         offset += 2;
228
229         /*
230          * We set the actual length of the tvbuff for the interleaved
231          * stuff to the minimum of what's left in the tvbuff and the
232          * length in the header.
233          *
234          * XXX - what if there's nothing left in the tvbuff?
235          * We'd want a BoundsError exception to be thrown, so
236          * that a Short Frame would be reported.
237          */
238         if (length_remaining > rf_len)
239                 length_remaining = rf_len;
240         next_tvb = tvb_new_subset(tvb, offset, length_remaining, rf_len);
241
242         conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
243                 pinfo->srcport, pinfo->destport, 0);
244
245         if (conv &&
246             (data = conversation_get_proto_data(conv, proto_rtsp)) &&
247             /* Add the following condition if it is not always true.
248             rf_chan < RTSP_MAX_INTERLEAVED &&
249             */
250             (dissector = data->interleaved[rf_chan].dissector)) {
251                 call_dissector(dissector, next_tvb, pinfo, tree);
252         } else {
253                 proto_tree_add_text(rtspframe_tree, tvb, offset, rf_len,
254                         "Data (%u bytes)", rf_len);
255         }
256
257         offset += rf_len;
258
259         return offset - orig_offset;
260 }
261
262 static void process_rtsp_request(tvbuff_t *tvb, int offset, const guchar *data,
263                                  size_t linelen, size_t next_line_offset,
264                                  proto_tree *tree);
265
266 static void process_rtsp_reply(tvbuff_t *tvb, int offset, const guchar *data,
267                                size_t linelen, size_t next_line_offset,
268                                proto_tree *tree);
269
270 typedef enum {
271         RTSP_REQUEST,
272         RTSP_REPLY,
273         RTSP_NOT_FIRST_LINE
274 } rtsp_type_t;
275
276 static const char *rtsp_methods[] = {
277         "DESCRIBE",
278         "ANNOUNCE",
279         "GET_PARAMETER",
280         "OPTIONS",
281         "PAUSE",
282         "PLAY",
283         "RECORD",
284         "REDIRECT",
285         "SETUP",
286         "SET_PARAMETER",
287         "TEARDOWN"
288 };
289
290 #define RTSP_NMETHODS   (sizeof rtsp_methods / sizeof rtsp_methods[0])
291
292 static gboolean
293 is_rtsp_request_or_reply(const guchar *line, size_t linelen, rtsp_type_t *type)
294 {
295         unsigned        ii;
296
297         /* Is this an RTSP reply? */
298         if (linelen >= 5 && g_ascii_strncasecmp("RTSP/", line, 5) == 0) {
299                 /*
300                  * Yes.
301                  */
302                 *type = RTSP_REPLY;
303                 return TRUE;
304         }
305
306         /*
307          * Is this an RTSP request?
308          * Check whether the line begins with one of the RTSP request
309          * methods.
310          */
311         for (ii = 0; ii < RTSP_NMETHODS; ii++) {
312                 size_t len = strlen(rtsp_methods[ii]);
313                 if (linelen >= len &&
314                     g_ascii_strncasecmp(rtsp_methods[ii], line, len) == 0 &&
315                     (len == linelen || isspace(line[len])))
316                 {
317                         *type = RTSP_REQUEST;
318                         return TRUE;
319                 }
320         }
321
322         /* Wasn't a request or a response */
323         *type = RTSP_NOT_FIRST_LINE;
324         return FALSE;
325 }
326
327 static const char rtsp_content_type[] = "Content-Type:";
328 static const char rtsp_transport[] = "Transport:";
329 static const char rtsp_sps[] = "server_port=";
330 static const char rtsp_cps[] = "client_port=";
331 static const char rtsp_rtp[] = "rtp/";
332 static const char rtsp_rdt_feature_level[] = "RDTFeatureLevel";
333 static const char rtsp_real_rdt[] = "x-real-rdt/";
334 static const char rtsp_real_tng[] = "x-pn-tng/"; /* synonym for x-real-rdt */
335 static const char rtsp_inter[] = "interleaved=";
336
337 static void
338 rtsp_create_conversation(packet_info *pinfo, const guchar *line_begin,
339                          size_t line_len, gint rdt_feature_level)
340 {
341         conversation_t  *conv;
342         guchar          buf[256];
343         guchar          *tmp;
344         gboolean        rtp_transport = FALSE;
345         gboolean        rdt_transport = FALSE;
346         guint           c_data_port, c_mon_port;
347         guint           s_data_port, s_mon_port;
348         gboolean        is_video = FALSE; /* FIX ME - need to indicate video or not */
349
350         /* Copy line into buf */
351         if (line_len > sizeof(buf) - 1)
352         {
353                 /* Don't overflow the buffer. */
354                 line_len = sizeof(buf) - 1;
355         }
356         memcpy(buf, line_begin, line_len);
357         buf[line_len] = '\0';
358
359         /* Get past "Transport:" and spaces */ 
360         tmp = buf + STRLEN_CONST(rtsp_transport);
361         while (*tmp && isspace(*tmp))
362                 tmp++;
363
364         /* Work out which transport type is here */
365         if (g_ascii_strncasecmp(tmp, rtsp_rtp, strlen(rtsp_rtp)) == 0)
366                 rtp_transport = TRUE;
367         else
368         if (g_ascii_strncasecmp(tmp, rtsp_real_rdt, strlen(rtsp_real_rdt)) == 0 ||
369             g_ascii_strncasecmp(tmp, rtsp_real_tng, strlen(rtsp_real_tng)) == 0)
370                 rdt_transport = TRUE;
371         else
372         {
373                 /* Give up on unknown transport types */
374                 return;
375         }
376         
377         c_data_port = c_mon_port = 0;
378         s_data_port = s_mon_port = 0;
379         
380         /* Look for server port */
381         if ((tmp = strstr(buf, rtsp_sps))) {
382                 tmp += strlen(rtsp_sps);
383                 if (sscanf(tmp, "%u-%u", &s_data_port, &s_mon_port) < 1) {
384                         g_warning("Frame %u: rtsp: bad server_port",
385                                 pinfo->fd->num);
386                         return;
387                 }
388         }
389         /* Look for client port */
390         if ((tmp = strstr(buf, rtsp_cps))) {
391                 tmp += strlen(rtsp_cps);
392                 if (sscanf(tmp, "%u-%u", &c_data_port, &c_mon_port) < 1) {
393                         g_warning("Frame %u: rtsp: bad client_port",
394                                 pinfo->fd->num);
395                         return;
396                 }
397         }
398         
399         
400         /* Deal with RTSP TCP-interleaved conversations. */
401         if (!c_data_port) {
402                 rtsp_conversation_data_t        *data;
403                 guint                           s_data_chan, s_mon_chan;
404                 int                             i;
405
406                 /* Search tranport line for interleaved string */
407                 if ((tmp = strstr(buf, rtsp_inter)) == NULL) {
408                         /*
409                          * No interleaved or server_port - probably a
410                          * SETUP request, rather than reply.
411                          */
412                         return;
413                 }
414                 
415                 /* Move tmp to beyone interleaved string */
416                 tmp += strlen(rtsp_inter);
417                 /* Look for channel number(s) */
418                 i = sscanf(tmp, "%u-%u", &s_data_chan, &s_mon_chan);
419                 if (i < 1)
420                 {
421                         g_warning("Frame %u: rtsp: bad interleaved", pinfo->fd->num);
422                         return;
423                 }
424                 
425                 /* At least data channel present, look for conversation (presumably TCP) */
426                 conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
427                                          pinfo->srcport, pinfo->destport, 0);
428
429                 /* Create new conversation if necessary */
430                 if (!conv)
431                 {
432                         conv = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
433                                                 pinfo->ptype, pinfo->srcport, pinfo->destport,
434                                                 0);
435                 }
436                 
437                 /* Look for previous data */
438                 data = conversation_get_proto_data(conv, proto_rtsp);
439
440                 /* Create new data if necessary */
441                 if (!data)
442                 {
443                         data = se_alloc(sizeof(rtsp_conversation_data_t));
444                         conversation_add_proto_data(conv, proto_rtsp, data);
445                 }
446
447                 /* Now set the dissector handle of the interleaved channel
448                    according to the transport protocol used */
449                 if (rtp_transport)
450                 {
451                         if (s_data_chan < RTSP_MAX_INTERLEAVED) {
452                                 data->interleaved[s_data_chan].dissector =
453                                         rtp_handle;
454                         }
455                         if (i > 1 && s_mon_chan < RTSP_MAX_INTERLEAVED) {
456                                 data->interleaved[s_mon_chan].dissector =
457                                         rtcp_handle;
458                         }
459                 }
460                 else if (rdt_transport)
461                 {
462                         if (s_data_chan < RTSP_MAX_INTERLEAVED) {
463                                 data->interleaved[s_data_chan].dissector =
464                                         rdt_handle;
465                         }
466                 }
467                 return;
468         }
469
470         /*
471          * We only want to match on the destination address, not the
472          * source address, because the server might send back a packet
473          * from an address other than the address to which its client
474          * sent the packet, so we construct a conversation with no
475          * second address.
476          */
477         if (rtp_transport)
478         {
479                 /* There is always data for RTP */
480                 rtp_add_address(pinfo, &pinfo->dst, c_data_port, s_data_port,
481                                 "RTSP", pinfo->fd->num, is_video, NULL);
482         
483                 /* RTCP only if indicated */
484                 if (c_mon_port)
485                 {
486                         rtcp_add_address(pinfo, &pinfo->dst, c_mon_port, s_mon_port,
487                                          "RTSP", pinfo->fd->num);
488                 }
489         }
490         else
491         if (rdt_transport)
492         {
493                 /* Real Data Transport */
494                 rdt_add_address(pinfo, &pinfo->dst, c_data_port, s_data_port,
495                                 "RTSP", rdt_feature_level);
496         }
497 }
498
499 static const char rtsp_content_length[] = "Content-Length:";
500
501 static int
502 rtsp_get_content_length(const guchar *line_begin, size_t line_len)
503 {
504         guchar          buf[256];
505         guchar          *tmp;
506         long            content_length;
507         char            *p;
508         guchar          *up;
509
510         if (line_len > sizeof(buf) - 1) {
511                 /*
512                  * Don't overflow the buffer.
513                  */
514                 line_len = sizeof(buf) - 1;
515         }
516         memcpy(buf, line_begin, line_len);
517         buf[line_len] = '\0';
518
519         tmp = buf + STRLEN_CONST(rtsp_content_length);
520         while (*tmp && isspace(*tmp))
521                 tmp++;
522         content_length = strtol(tmp, &p, 10);
523         up = p;
524         if (up == tmp || (*up != '\0' && !isspace(*up)))
525                 return -1;      /* not a valid number */
526         return content_length;
527 }
528
529 static const char rtsp_Session[] = "Session:";
530 static const char rtsp_X_Vig_Msisdn[] = "X-Vig-Msisdn";
531
532 static int
533 dissect_rtspmessage(tvbuff_t *tvb, int offset, packet_info *pinfo,
534         proto_tree *tree)
535 {
536         proto_tree              *rtsp_tree = NULL;
537         proto_tree              *sub_tree = NULL;
538         proto_item              *ti = NULL;
539         const guchar            *line;
540         gint                    next_offset;
541         const guchar            *linep, *lineend;
542         int                     orig_offset;
543         int                     first_linelen, linelen;
544         int                     line_end_offset;
545         int                     colon_offset;
546         gboolean                is_request_or_reply;
547         gboolean                body_requires_content_len;
548         gboolean                saw_req_resp_or_header;
549         guchar                  c;
550         rtsp_type_t             rtsp_type;
551         gboolean                is_header;
552         int                     datalen;
553         int                     content_length;
554         int                     reported_datalen;
555         int                     value_offset;
556         int                     value_len;
557         e164_info_t             e164_info;
558         gint                    rdt_feature_level = 0;
559         gchar                   *media_type_str_lower_case = NULL;
560         int                     semi_colon_offset;
561         int                     par_end_offset;
562         gchar   *frame_label = NULL;
563         gchar   *session_id = NULL;
564         voip_packet_info_t *stat_info = NULL;
565
566         /*
567          * Is this a request or response?
568          *
569          * Note that "tvb_find_line_end()" will return a value that
570          * is not longer than what's in the buffer, so the
571          * "tvb_get_ptr()" call won't throw an exception.
572          */
573         first_linelen = tvb_find_line_end(tvb, offset,
574             tvb_ensure_length_remaining(tvb, offset), &next_offset,
575             FALSE);
576
577         /*
578          * Is the first line a request or response?
579          */
580         line = tvb_get_ptr(tvb, offset, first_linelen);
581         is_request_or_reply = is_rtsp_request_or_reply(line, first_linelen,
582             &rtsp_type);
583         if (is_request_or_reply) {
584                 /*
585                  * Yes, it's a request or response.
586                  * Do header desegmentation if we've been told to,
587                  * and do body desegmentation if we've been told to and
588                  * we find a Content-Length header.
589                  */
590                 if (!req_resp_hdrs_do_reassembly(tvb, offset, pinfo,
591                     rtsp_desegment_headers, rtsp_desegment_body)) {
592                         /*
593                          * More data needed for desegmentation.
594                          */
595                         return -1;
596                 }
597         }
598
599         /*
600          * RFC 2326 says that a content length must be specified
601          * in requests that have a body, although section 4.4 speaks
602          * of a server closing the connection indicating the end of
603          * a reply body.
604          *
605          * We assume that an absent content length in a request means
606          * that we don't have a body, and that an absent content length
607          * in a reply means that the reply body runs to the end of
608          * the connection.  If the first line is neither, we assume
609          * that whatever follows a blank line should be treated as a
610          * body; there's not much else we can do, as we're jumping
611          * into the message in the middle.
612          *
613          * XXX - if there was no Content-Length entity header, we should
614          * accumulate all data until the end of the connection.
615          * That'd require that the TCP dissector call subdissectors
616          * for all frames with FIN, even if they contain no data,
617          * which would require subdissectors to deal intelligently
618          * with empty segments.
619          */
620         if (rtsp_type == RTSP_REQUEST)
621                 body_requires_content_len = TRUE;
622         else
623                 body_requires_content_len = FALSE;
624
625         line = tvb_get_ptr(tvb, offset, first_linelen);
626         if (is_request_or_reply) {
627                 if ( rtsp_type == RTSP_REPLY ) {
628                         frame_label = ep_strdup_printf("Reply: %s", format_text(line, first_linelen));
629                 }
630                 else {
631                         frame_label = ep_strdup(format_text(line, first_linelen));
632                 }
633         }
634
635         col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTSP");
636         if (check_col(pinfo->cinfo, COL_INFO)) {
637                 /*
638                  * Put the first line from the buffer into the summary
639                  * if it's an RTSP request or reply (but leave out the
640                  * line terminator).
641                  * Otherwise, just call it a continuation.
642                  *
643                  * Note that "tvb_find_line_end()" will return a value that
644                  * is not longer than what's in the buffer, so the
645                  * "tvb_get_ptr()" call won't throw an exception.
646                  */
647                 if (is_request_or_reply)
648                         if ( rtsp_type == RTSP_REPLY ) {
649                                 col_set_str(pinfo->cinfo, COL_INFO, "Reply: ");
650                                 col_append_str(pinfo->cinfo, COL_INFO,
651                                         format_text(line, first_linelen));
652                         }
653                         else {
654                                 col_add_str(pinfo->cinfo, COL_INFO,
655                                         format_text(line, first_linelen));
656                         }
657
658                 else
659                         col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
660
661         }
662
663         orig_offset = offset;
664         if (tree) {
665                 ti = proto_tree_add_item(tree, proto_rtsp, tvb, offset, -1,
666                     FALSE);
667                 rtsp_tree = proto_item_add_subtree(ti, ett_rtsp);
668         }
669
670         /*
671          * We haven't yet seen a Content-Length header.
672          */
673         content_length = -1;
674
675         /*
676          * Process the packet data, a line at a time.
677          */
678         saw_req_resp_or_header = FALSE; /* haven't seen anything yet */
679         while (tvb_reported_length_remaining(tvb, offset) != 0) {
680                 /*
681                  * We haven't yet concluded that this is a header.
682                  */
683                 is_header = FALSE;
684
685                 /*
686                  * Find the end of the line.
687                  */
688                 linelen = tvb_find_line_end(tvb, offset,
689                     tvb_ensure_length_remaining(tvb, offset), &next_offset,
690                     FALSE);
691                 if (linelen < 0)
692                         return -1;
693                 line_end_offset = offset + linelen;
694                 /*
695                  * colon_offset may be -1
696                  */
697                 colon_offset = tvb_find_guint8(tvb, offset, linelen, ':');
698
699
700                 /*
701                  * Get a buffer that refers to the line.
702                  */
703                 line = tvb_get_ptr(tvb, offset, linelen);
704                 lineend = line + linelen;
705
706                 /*
707                  * OK, does it look like an RTSP request or response?
708                  */
709                 is_request_or_reply = is_rtsp_request_or_reply(line, linelen, &rtsp_type);
710                 if (is_request_or_reply)
711                         goto is_rtsp;
712
713                 /*
714                  * No.  Does it look like a blank line (as would appear
715                  * at the end of an RTSP request)?
716                  */
717                 if (linelen == 0)
718                         goto is_rtsp;   /* Yes. */
719
720                 /*
721                  * No.  Does it look like a header?
722                  */
723                 linep = line;
724                 while (linep < lineend) {
725                         c = *linep++;
726
727                         /*
728                          * This must be a CHAR to be part of a token; that
729                          * means it must be ASCII.
730                          */
731                         if (!isascii(c))
732                                 break;  /* not ASCII, thus not a CHAR */
733
734                         /*
735                          * This mustn't be a CTL to be part of a token.
736                          *
737                          * XXX - what about leading LWS on continuation
738                          * lines of a header?
739                          */
740                         if (iscntrl(c))
741                                 break;  /* CTL, not part of a header */
742
743                         switch (c) {
744
745                         case '(':
746                         case ')':
747                         case '<':
748                         case '>':
749                         case '@':
750                         case ',':
751                         case ';':
752                         case '\\':
753                         case '"':
754                         case '/':
755                         case '[':
756                         case ']':
757                         case '?':
758                         case '=':
759                         case '{':
760                         case '}':
761                                 /*
762                                  * It's a tspecial, so it's not
763                                  * part of a token, so it's not
764                                  * a field name for the beginning
765                                  * of a header.
766                                  */
767                                 goto not_rtsp;
768
769                         case ':':
770                                 /*
771                                  * This ends the token; we consider
772                                  * this to be a header.
773                                  */
774                                 is_header = TRUE;
775                                 goto is_rtsp;
776
777                         case ' ':
778                         case '\t':
779                                 /*
780                                  * LWS (RFC-2616, 4.2); continue the previous
781                                  * header.
782                                  */
783                                 goto is_rtsp;
784                         }
785                 }
786
787                 /*
788                  * We haven't seen the colon, but everything else looks
789                  * OK for a header line.
790                  *
791                  * If we've already seen an RTSP request or response
792                  * line, or a header line, and we're at the end of
793                  * the tvbuff, we assume this is an incomplete header
794                  * line.  (We quit this loop after seeing a blank line,
795                  * so if we've seen a request or response line, or a
796                  * header line, this is probably more of the request
797                  * or response we're presumably seeing.  There is some
798                  * risk of false positives, but the same applies for
799                  * full request or response lines or header lines,
800                  * although that's less likely.)
801                  *
802                  * We throw an exception in that case, by checking for
803                  * the existence of the next byte after the last one
804                  * in the line.  If it exists, "tvb_ensure_bytes_exist()"
805                  * throws no exception, and we fall through to the
806                  * "not RTSP" case.  If it doesn't exist,
807                  * "tvb_ensure_bytes_exist()" will throw the appropriate
808                  * exception.
809                  */
810                 if (saw_req_resp_or_header)
811                         tvb_ensure_bytes_exist(tvb, offset, linelen + 1);
812
813         not_rtsp:
814                 /*
815                  * We don't consider this part of an RTSP request or
816                  * reply, so we don't display it.
817                  */
818                 break;
819
820         is_rtsp:
821                 /*
822                  * Process this line.
823                  */
824                 if (linelen == 0) {
825                         /*
826                          * This is a blank line, which means that
827                          * whatever follows it isn't part of this
828                          * request or reply.
829                          */
830                         proto_tree_add_text(rtsp_tree, tvb, offset,
831                                             next_offset - offset, "%s",
832                                             tvb_format_text(tvb, offset, next_offset - offset));
833                         offset = next_offset;
834                         break;
835                 }
836
837                 /*
838                  * Not a blank line - either a request, a reply, or a header
839                  * line.
840                  */
841                 saw_req_resp_or_header = TRUE;
842                 if (rtsp_tree) {
843
844                         switch (rtsp_type)
845                         {
846                                 case RTSP_REQUEST:
847                                         process_rtsp_request(tvb, offset, line, linelen, next_offset, rtsp_tree);
848                                         break;
849         
850                                 case RTSP_REPLY:
851                                         process_rtsp_reply(tvb, offset, line, linelen, next_offset, rtsp_tree);
852                                         break;
853         
854                                 case RTSP_NOT_FIRST_LINE:
855                                         /* Drop through, it may well be a header line */
856                                         break;
857                         }
858                 }
859
860                 if (is_header)
861                 {
862                         /* We know that colon_offset must be set */
863                         
864                         /* Skip whitespace after the colon. */
865                         value_offset = colon_offset + 1;
866                         while ((value_offset < line_end_offset) &&
867                                    ((c = tvb_get_guint8(tvb, value_offset)) == ' ' || c == '\t'))
868                         {
869                                 value_offset++;
870                         }
871                         value_len = line_end_offset - value_offset;
872
873                         /*
874                          * Process some headers specially.
875                          */
876 #define HDR_MATCHES(header) \
877         ( (size_t)linelen > STRLEN_CONST(header) && \
878          g_ascii_strncasecmp(line, (header), STRLEN_CONST(header)) == 0)
879
880                         if (HDR_MATCHES(rtsp_transport))
881                         {
882                                 proto_tree_add_string(rtsp_tree, hf_rtsp_transport, tvb,
883                                                       offset, linelen,
884                                                       tvb_format_text(tvb, value_offset,
885                                                                       value_len));
886
887                                 /*
888                                  * Based on the port numbers specified
889                                  * in the Transport: header, set up
890                                  * a conversation that will be dissected
891                                  * with the appropriate dissector.
892                                  */
893                                 rtsp_create_conversation(pinfo, line, linelen, rdt_feature_level);
894                         } else if (HDR_MATCHES(rtsp_content_type))
895                         {
896                                 proto_tree_add_string(rtsp_tree, hf_rtsp_content_type,
897                                                       tvb, offset, linelen,
898                                                       tvb_format_text(tvb, value_offset,
899                                                                       value_len));
900
901                                 offset = offset + STRLEN_CONST(rtsp_content_type);
902                                 /* Skip wsp */
903                                 offset = tvb_skip_wsp(tvb, offset, value_len);
904                                 semi_colon_offset = tvb_find_guint8(tvb, value_offset, value_len, ';');
905                                 if ( semi_colon_offset != -1) {
906                                         /* m-parameter present */
907                                         par_end_offset = tvb_skip_wsp_return(tvb, semi_colon_offset-1);
908                                         value_len = par_end_offset - offset;
909                                 }
910
911                                 media_type_str_lower_case = ascii_strdown_inplace(
912                                     (gchar *)tvb_get_ephemeral_string(tvb, offset, value_len));
913
914                         } else if (HDR_MATCHES(rtsp_content_length))
915                         {
916                                 proto_tree_add_uint(rtsp_tree, hf_rtsp_content_length,
917                                                     tvb, offset, linelen,
918                                                     atoi(tvb_format_text(tvb, value_offset,
919                                                                          value_len)));
920
921                                 /*
922                                  * Only the amount specified by the
923                                  * Content-Length: header should be treated
924                                  * as payload.
925                                  */
926                                 content_length = rtsp_get_content_length(line, linelen);
927
928                         } else if (HDR_MATCHES(rtsp_Session))
929                         {
930                                 session_id = tvb_format_text(tvb, value_offset, value_len);
931                                 /* Put the value into the protocol tree */
932                                 proto_tree_add_string(rtsp_tree, hf_rtsp_session, tvb,
933                                                       offset, linelen,
934                                                       session_id);
935
936                         } else if (HDR_MATCHES(rtsp_X_Vig_Msisdn)) {
937                                 /*
938                                  * Extract the X_Vig_Msisdn string
939                                  */
940                                 if (colon_offset != -1)
941                                 {
942                                         /* Put the value into the protocol tree */
943                                         ti = proto_tree_add_string(rtsp_tree, hf_rtsp_X_Vig_Msisdn,tvb,
944                                                                    offset, linelen ,
945                                                                    tvb_format_text(tvb, value_offset, value_len));
946                                         sub_tree = proto_item_add_subtree(ti, ett_rtsp_method);
947
948                                         e164_info.e164_number_type = CALLING_PARTY_NUMBER;
949                                         e164_info.nature_of_address = 0;
950
951                                         e164_info.E164_number_str = tvb_get_ephemeral_string(tvb, value_offset,
952                                                                                       value_len);
953                                         e164_info.E164_number_length = value_len;
954                                         dissect_e164_number(tvb, sub_tree, value_offset,
955                                                             value_len, e164_info);
956                                 }
957                         } else if (HDR_MATCHES(rtsp_rdt_feature_level))
958                         {
959                                 rdt_feature_level = atoi(tvb_format_text(tvb, value_offset,
960                                                                          value_len));
961                                 proto_tree_add_uint(rtsp_tree, hf_rtsp_rdtfeaturelevel,
962                                                     tvb, offset, linelen,
963                                                     atoi(tvb_format_text(tvb, value_offset,
964                                                                          value_len)));
965                         }
966                         else
967                         {
968                                 /* Default case for headers. Show line as text */
969                                 proto_tree_add_text(rtsp_tree, tvb, offset,
970                                                     next_offset - offset, "%s",
971                                                     tvb_format_text(tvb, offset, next_offset - offset));
972                         }
973                 }
974                 else if (rtsp_type == RTSP_NOT_FIRST_LINE)
975                 {
976                         /* Catch-all for all other lines... Show line as text.
977                            TODO: should these be shown as errors? */
978                         proto_tree_add_text(rtsp_tree, tvb, offset,
979                                             next_offset - offset, "%s",
980                                             tvb_format_text(tvb, offset, next_offset - offset));
981                 }
982                 
983                 offset = next_offset;
984         }
985
986         if (session_id) {
987                 stat_info = ep_alloc0(sizeof(voip_packet_info_t));
988                 stat_info->protocol_name = ep_strdup("RTSP");
989                 stat_info->call_id = session_id;
990                 stat_info->frame_label = frame_label;
991                 stat_info->call_state = VOIP_CALL_SETUP;
992                 stat_info->call_active_state = VOIP_NO_STATE;
993                 stat_info->frame_comment = frame_label;
994                 tap_queue_packet(voip_tap, pinfo, stat_info);
995         }
996
997         /*
998          * Have now read all of the lines of this message.
999          *
1000          * If a content length was supplied, the amount of data to be
1001          * processed as RTSP payload is the minimum of the content
1002          * length and the amount of data remaining in the frame.
1003          *
1004          * If no content length was supplied (or if a bad content length
1005          * was supplied), the amount of data to be processed is the amount
1006          * of data remaining in the frame.
1007          */
1008         datalen = tvb_length_remaining(tvb, offset);
1009         reported_datalen = tvb_reported_length_remaining(tvb, offset);
1010         if (content_length != -1) {
1011                 /*
1012                  * Content length specified; display only that amount
1013                  * as payload.
1014                  */
1015                 if (datalen > content_length)
1016                         datalen = content_length;
1017
1018                 /*
1019                  * XXX - limit the reported length in the tvbuff we'll
1020                  * hand to a subdissector to be no greater than the
1021                  * content length.
1022                  *
1023                  * We really need both unreassembled and "how long it'd
1024                  * be if it were reassembled" lengths for tvbuffs, so
1025                  * that we throw the appropriate exceptions for
1026                  * "not enough data captured" (running past the length),
1027                  * "packet needed reassembly" (within the length but
1028                  * running past the unreassembled length), and
1029                  * "packet is malformed" (running past the reassembled
1030                  * length).
1031                  */
1032                 if (reported_datalen > content_length)
1033                         reported_datalen = content_length;
1034         } else {
1035                 /*
1036                  * No content length specified; if this message doesn't
1037                  * have a body if no content length is specified, process
1038                  * nothing as payload.
1039                  */
1040                 if (body_requires_content_len)
1041                         datalen = 0;
1042         }
1043
1044         if (datalen > 0) {
1045                 /*
1046                  * There's stuff left over; process it.
1047                  */
1048                 tvbuff_t *new_tvb;
1049
1050                 /*
1051                  * Now create a tvbuff for the Content-type stuff and
1052                  * dissect it.
1053                  *
1054                  * The amount of data to be processed that's
1055                  * available in the tvbuff is "datalen", which
1056                  * is the minimum of the amount of data left in
1057                  * the tvbuff and any specified content length.
1058                  *
1059                  * The amount of data to be processed that's in
1060                  * this frame, regardless of whether it was
1061                  * captured or not, is "reported_datalen",
1062                  * which, if no content length was specified,
1063                  * is -1, i.e. "to the end of the frame.
1064                  */
1065                 new_tvb = tvb_new_subset(tvb, offset, datalen,
1066                             reported_datalen);
1067
1068                 if (media_type_str_lower_case && 
1069                         dissector_try_string(media_type_dissector_table,
1070                                 media_type_str_lower_case,
1071                                 new_tvb, pinfo, rtsp_tree)){
1072                         
1073                 }else {
1074                         /*
1075                          * Fix up the top-level item so that it doesn't
1076                          * include the SDP stuff.
1077                          */
1078                         if (ti != NULL)
1079                                 proto_item_set_len(ti, offset);
1080
1081                         if (tvb_get_guint8(tvb, offset) == RTSP_FRAMEHDR) {
1082                                 /*
1083                                  * This is interleaved stuff; don't
1084                                  * treat it as raw data - set "datalen"
1085                                  * to 0, so we won't skip the offset
1086                                  * past it, which will cause our
1087                                  * caller to process that stuff itself.
1088                                  */
1089                                 datalen = 0;
1090                         } else {
1091                                 proto_tree_add_text(rtsp_tree, tvb, offset,
1092                                     datalen, "Data (%d bytes)",
1093                                     reported_datalen);
1094                         }
1095                 }
1096
1097                 /*
1098                  * We've processed "datalen" bytes worth of data
1099                  * (which may be no data at all); advance the
1100                  * offset past whatever data we've processed.
1101                  */
1102                 offset += datalen;
1103         }
1104         return offset - orig_offset;
1105 }
1106
1107 static void
1108 process_rtsp_request(tvbuff_t *tvb, int offset, const guchar *data,
1109                      size_t linelen, size_t next_line_offset, proto_tree *tree)
1110 {
1111         proto_tree              *sub_tree = NULL;
1112         proto_item              *ti = NULL;
1113         const guchar    *lineend = data + linelen;
1114         unsigned                ii;
1115         const guchar    *url;
1116         const guchar    *url_start;
1117         guchar                  *tmp_url;
1118
1119         /* Request Methods */
1120         for (ii = 0; ii < RTSP_NMETHODS; ii++) {
1121                 size_t len = strlen(rtsp_methods[ii]);
1122                 if (linelen >= len &&
1123                     g_ascii_strncasecmp(rtsp_methods[ii], data, len) == 0 &&
1124                     (len == linelen || isspace(data[len])))
1125                         break;
1126         }
1127         if (ii == RTSP_NMETHODS) {
1128                 /*
1129                  * We got here because "is_rtsp_request_or_reply()" returned
1130                  * RTSP_REQUEST, so we know one of the request methods
1131                  * matched, so we "can't get here".
1132                  */
1133                 DISSECTOR_ASSERT_NOT_REACHED();
1134         }
1135
1136         /* Add a tree for this request */
1137         ti = proto_tree_add_string(tree, hf_rtsp_request, tvb, offset,
1138                                   (gint) (next_line_offset - offset),
1139                                   tvb_format_text(tvb, offset, (gint) (next_line_offset - offset)));
1140         sub_tree = proto_item_add_subtree(ti, ett_rtsp_method);
1141
1142         
1143         /* Add method name to tree */
1144         proto_tree_add_string(sub_tree, hf_rtsp_method, tvb, offset,
1145                               (gint) strlen(rtsp_methods[ii]), rtsp_methods[ii]);
1146
1147         /* URL */
1148         url = data;
1149         /* Skip method name again */
1150         while (url < lineend && !isspace(*url))
1151                 url++;
1152         /* Skip spaces */
1153         while (url < lineend && isspace(*url))
1154                 url++;
1155         /* URL starts here */
1156         url_start = url;
1157         /* Scan to end of URL */
1158         while (url < lineend && !isspace(*url))
1159                 url++;
1160         /* Create a URL-sized buffer and copy contents */
1161         tmp_url = ep_strndup(url_start, url - url_start);
1162         
1163         /* Add URL to tree */
1164         proto_tree_add_string(sub_tree, hf_rtsp_url, tvb,
1165                               offset + (gint) (url_start - data), (gint) (url - url_start), tmp_url);
1166 }
1167
1168 /* Read first line of a reply message */
1169 static void
1170 process_rtsp_reply(tvbuff_t *tvb, int offset, const guchar *data,
1171         size_t linelen, size_t next_line_offset, proto_tree *tree)
1172 {
1173         proto_tree              *sub_tree = NULL;
1174         proto_item              *ti = NULL;
1175         const guchar    *lineend = data + linelen;
1176         const guchar    *status = data;
1177         const guchar    *status_start;
1178         unsigned int    status_i;
1179
1180         /* Add a tree for this request */
1181         ti = proto_tree_add_string(tree, hf_rtsp_response, tvb, offset,
1182                                    (gint) (next_line_offset - offset),
1183                                    tvb_format_text(tvb, offset, (gint) (next_line_offset - offset)));
1184         sub_tree = proto_item_add_subtree(ti, ett_rtsp_method);
1185
1186
1187         /* status code */
1188         
1189         /* Skip protocol/version */
1190         while (status < lineend && !isspace(*status))
1191                 status++;
1192         /* Skip spaces */
1193         while (status < lineend && isspace(*status))
1194                 status++;
1195
1196         /* Actual code number now */
1197         status_start = status;
1198         status_i = 0;
1199         while (status < lineend && isdigit(*status))
1200                 status_i = status_i * 10 + *status++ - '0';
1201         
1202         /* Add field to tree */
1203         proto_tree_add_uint(sub_tree, hf_rtsp_status, tvb,
1204                             offset + (gint) (status_start - data),
1205                             (gint) (status - status_start), status_i);
1206 }
1207
1208 static void
1209 dissect_rtsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1210 {
1211         int             offset = 0;
1212         int             len;
1213
1214         while (tvb_reported_length_remaining(tvb, offset) != 0) {
1215                 len = (tvb_get_guint8(tvb, offset) == RTSP_FRAMEHDR)
1216                         ? dissect_rtspinterleaved(tvb, offset, pinfo, tree)
1217                         : dissect_rtspmessage(tvb, offset, pinfo, tree);
1218                 if (len == -1)
1219                         break;
1220                 offset += len;
1221
1222                 /*
1223                  * OK, we've set the Protocol and Info columns for the
1224                  * first RTSP message; make the columns non-writable,
1225                  * so that we don't change it for subsequent RTSP messages.
1226                  */
1227                 col_set_writable(pinfo->cinfo, FALSE);
1228         }
1229 }
1230
1231 void
1232 proto_register_rtsp(void)
1233 {
1234         static gint *ett[] = {
1235                 &ett_rtspframe,
1236                 &ett_rtsp,
1237                 &ett_rtsp_method,
1238         };
1239         static hf_register_info hf[] = {
1240                 { &hf_rtsp_request,
1241                         { "Request", "rtsp.request", FT_STRING, BASE_NONE, NULL, 0,
1242                         NULL, HFILL }},
1243                 { &hf_rtsp_response,
1244                         { "Response", "rtsp.response", FT_STRING, BASE_NONE, NULL, 0,
1245                         NULL, HFILL }},
1246                 { &hf_rtsp_method,
1247                         { "Method", "rtsp.method", FT_STRING, BASE_NONE, NULL, 0,
1248                         NULL, HFILL }},
1249                 { &hf_rtsp_content_type,
1250                         { "Content-type", "rtsp.content-type", FT_STRING, BASE_NONE, NULL, 0,
1251                         NULL, HFILL }},
1252                 { &hf_rtsp_content_length,
1253                         { "Content-length", "rtsp.content-length", FT_UINT32, BASE_DEC, NULL, 0,
1254                         NULL, HFILL }},
1255                 { &hf_rtsp_url,
1256                         { "URL", "rtsp.url", FT_STRING, BASE_NONE, NULL, 0,
1257                         NULL, HFILL }},
1258                 { &hf_rtsp_status,
1259                         { "Status", "rtsp.status", FT_UINT32, BASE_DEC, NULL, 0,
1260                         NULL, HFILL }},
1261                 { &hf_rtsp_session,
1262                         { "Session", "rtsp.session", FT_STRING, BASE_NONE, NULL, 0,
1263                         NULL, HFILL }},
1264                 { &hf_rtsp_transport,
1265                         { "Transport", "rtsp.transport", FT_STRING, BASE_NONE, NULL, 0,
1266                         NULL, HFILL }},
1267                 { &hf_rtsp_rdtfeaturelevel,
1268                         { "RDTFeatureLevel", "rtsp.rdt-feature-level", FT_UINT32, BASE_DEC, NULL, 0,
1269                         NULL, HFILL }},
1270                 { &hf_rtsp_X_Vig_Msisdn,
1271                         { "X-Vig-Msisdn", "X_Vig_Msisdn", FT_STRING, BASE_NONE, NULL, 0,
1272                         NULL, HFILL }},
1273
1274
1275         };
1276         module_t *rtsp_module;
1277
1278         proto_rtsp = proto_register_protocol("Real Time Streaming Protocol",
1279                 "RTSP", "rtsp");
1280
1281         proto_register_field_array(proto_rtsp, hf, array_length(hf));
1282         proto_register_subtree_array(ett, array_length(ett));
1283
1284         /* Make this dissector findable by name */
1285         register_dissector("rtsp", dissect_rtsp, proto_rtsp);
1286
1287         /* Register our configuration options, particularly our ports */
1288
1289         rtsp_module = prefs_register_protocol(proto_rtsp, proto_reg_handoff_rtsp);
1290         prefs_register_uint_preference(rtsp_module, "tcp.port",
1291                 "RTSP TCP Port",
1292                 "Set the TCP port for RTSP messages",
1293                 10, &global_rtsp_tcp_port);
1294         prefs_register_uint_preference(rtsp_module, "tcp.alternate_port",
1295                 "Alternate RTSP TCP Port",
1296                 "Set the alternate TCP port for RTSP messages",
1297                 10, &global_rtsp_tcp_alternate_port);
1298         prefs_register_bool_preference(rtsp_module, "desegment_headers",
1299             "Reassemble RTSP headers spanning multiple TCP segments",
1300             "Whether the RTSP dissector should reassemble headers "
1301             "of a request spanning multiple TCP segments. "
1302             " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
1303             &rtsp_desegment_headers);
1304         prefs_register_bool_preference(rtsp_module, "desegment_body",
1305             "Trust the \"Content-length:\" header and\ndesegment RTSP "
1306             "bodies\nspanning multiple TCP segments",
1307             "Whether the RTSP dissector should use the "
1308             "\"Content-length:\" value to desegment the body "
1309             "of a request spanning multiple TCP segments",
1310             &rtsp_desegment_body);
1311
1312 }
1313
1314 void
1315 proto_reg_handoff_rtsp(void)
1316 {
1317         static dissector_handle_t rtsp_handle;
1318         static gboolean rtsp_prefs_initialized = FALSE;
1319         /*
1320          * Variables to allow for proper deletion of dissector registration when
1321          * the user changes port from the gui.
1322          */
1323         static guint saved_rtsp_tcp_port;
1324         static guint saved_rtsp_tcp_alternate_port;
1325
1326         if (!rtsp_prefs_initialized) {
1327                 rtsp_handle = find_dissector("rtsp");
1328                 rtp_handle = find_dissector("rtp");
1329                 rtcp_handle = find_dissector("rtcp");
1330                 rdt_handle = find_dissector("rdt");
1331                 media_type_dissector_table = find_dissector_table("media_type");
1332             voip_tap = find_tap_id("voip");
1333                 rtsp_prefs_initialized = TRUE;
1334         }
1335         else {
1336                 dissector_delete("tcp.port", saved_rtsp_tcp_port, rtsp_handle);
1337                 dissector_delete("tcp.port", saved_rtsp_tcp_alternate_port, rtsp_handle);
1338         }
1339         /* Set our port number for future use */
1340         dissector_add("tcp.port", global_rtsp_tcp_port, rtsp_handle);
1341         dissector_add("tcp.port", global_rtsp_tcp_alternate_port, rtsp_handle);
1342
1343         saved_rtsp_tcp_port = global_rtsp_tcp_port;
1344         saved_rtsp_tcp_alternate_port = global_rtsp_tcp_alternate_port;
1345
1346 }