]> git.sesse.net Git - vlc/blob - modules/stream_out/rtsp.c
wav: fix integer overflow (CVE-2008-2430)
[vlc] / modules / stream_out / rtsp.c
1 /*****************************************************************************
2  * rtsp.c: RTSP support for RTP stream output module
3  *****************************************************************************
4  * Copyright (C) 2003-2004 the VideoLAN team
5  * Copyright © 2007 Rémi Denis-Courmont
6  *
7  * $Id$
8  *
9  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_sout.h>
35
36 #include <vlc_httpd.h>
37 #include <vlc_url.h>
38 #include <vlc_network.h>
39 #include <vlc_rand.h>
40 #include <assert.h>
41 #include <errno.h>
42 #include <stdlib.h>
43
44 #include "rtp.h"
45
46 typedef struct rtsp_session_t rtsp_session_t;
47
48 struct rtsp_stream_t
49 {
50     vlc_mutex_t     lock;
51     sout_stream_t  *owner;
52     httpd_host_t   *host;
53     httpd_url_t    *url;
54     char           *psz_path;
55     const char     *track_fmt;
56     unsigned        port;
57
58     int             sessionc;
59     rtsp_session_t **sessionv;
60 };
61
62
63 static int  RtspCallback( httpd_callback_sys_t *p_args,
64                           httpd_client_t *cl, httpd_message_t *answer,
65                           const httpd_message_t *query );
66 static int  RtspCallbackId( httpd_callback_sys_t *p_args,
67                             httpd_client_t *cl, httpd_message_t *answer,
68                             const httpd_message_t *query );
69 static void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session );
70
71 rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url )
72 {
73     rtsp_stream_t *rtsp = malloc( sizeof( *rtsp ) );
74
75     if( rtsp == NULL || ( url->i_port > 99999 ) )
76     {
77         free( rtsp );
78         return NULL;
79     }
80
81     rtsp->owner = p_stream;
82     rtsp->sessionc = 0;
83     rtsp->sessionv = NULL;
84     rtsp->host = NULL;
85     rtsp->url = NULL;
86     rtsp->psz_path = NULL;
87     vlc_mutex_init( &rtsp->lock );
88
89     rtsp->port = (url->i_port > 0) ? url->i_port : 554;
90     rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" );
91     if( rtsp->psz_path == NULL )
92         goto error;
93
94     assert( strlen( rtsp->psz_path ) > 0 );
95     if( rtsp->psz_path[strlen( rtsp->psz_path ) - 1] == '/' )
96         rtsp->track_fmt = "%strackID=%u";
97     else
98         rtsp->track_fmt = "%s/trackID=%u";
99
100     msg_Dbg( p_stream, "RTSP stream: host %s port %d at %s",
101              url->psz_host, rtsp->port, rtsp->psz_path );
102
103     rtsp->host = httpd_HostNew( VLC_OBJECT(p_stream), url->psz_host,
104                                 rtsp->port );
105     if( rtsp->host == NULL )
106         goto error;
107
108     rtsp->url = httpd_UrlNewUnique( rtsp->host, rtsp->psz_path,
109                                     NULL, NULL, NULL );
110     if( rtsp->url == NULL )
111         goto error;
112
113     httpd_UrlCatch( rtsp->url, HTTPD_MSG_DESCRIBE, RtspCallback, (void*)rtsp );
114     httpd_UrlCatch( rtsp->url, HTTPD_MSG_SETUP,    RtspCallback, (void*)rtsp );
115     httpd_UrlCatch( rtsp->url, HTTPD_MSG_PLAY,     RtspCallback, (void*)rtsp );
116     httpd_UrlCatch( rtsp->url, HTTPD_MSG_PAUSE,    RtspCallback, (void*)rtsp );
117     httpd_UrlCatch( rtsp->url, HTTPD_MSG_GETPARAMETER, RtspCallback,
118                     (void*)rtsp );
119     httpd_UrlCatch( rtsp->url, HTTPD_MSG_TEARDOWN, RtspCallback, (void*)rtsp );
120     return rtsp;
121
122 error:
123     RtspUnsetup( rtsp );
124     return NULL;
125 }
126
127
128 void RtspUnsetup( rtsp_stream_t *rtsp )
129 {
130     while( rtsp->sessionc > 0 )
131         RtspClientDel( rtsp, rtsp->sessionv[0] );
132
133     if( rtsp->url )
134         httpd_UrlDelete( rtsp->url );
135
136     if( rtsp->host )
137         httpd_HostDelete( rtsp->host );
138
139     free( rtsp->psz_path );
140     vlc_mutex_destroy( &rtsp->lock );
141 }
142
143
144 struct rtsp_stream_id_t
145 {
146     rtsp_stream_t    *stream;
147     sout_stream_id_t *sout_id;
148     httpd_url_t      *url;
149     const char       *dst;
150     int               ttl;
151     uint32_t          ssrc;
152     uint16_t          loport, hiport;
153 };
154
155
156 typedef struct rtsp_strack_t rtsp_strack_t;
157
158 /* For unicast streaming */
159 struct rtsp_session_t
160 {
161     rtsp_stream_t *stream;
162     uint64_t       id;
163
164     /* output (id-access) */
165     int            trackc;
166     rtsp_strack_t *trackv;
167 };
168
169
170 /* Unicast session track */
171 struct rtsp_strack_t
172 {
173     sout_stream_id_t  *id;
174     int                fd;
175     bool         playing;
176 };
177
178
179 rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
180                              unsigned num, uint32_t ssrc,
181                              /* Multicast stuff - TODO: cleanup */
182                              const char *dst, int ttl,
183                              unsigned loport, unsigned hiport )
184 {
185     char urlbuf[sizeof( "/trackID=123" ) + strlen( rtsp->psz_path )];
186     rtsp_stream_id_t *id = malloc( sizeof( *id ) );
187     httpd_url_t *url;
188
189     if( id == NULL )
190         return NULL;
191
192     id->stream = rtsp;
193     id->sout_id = sid;
194     id->ssrc = ssrc;
195     /* TODO: can we assume that this need not be strdup'd? */
196     id->dst = dst;
197     if( id->dst != NULL )
198     {
199         id->ttl = ttl;
200         id->loport = loport;
201         id->hiport = hiport;
202     }
203
204     /* FIXME: num screws up if any ES has been removed and re-added */
205     snprintf( urlbuf, sizeof( urlbuf ), rtsp->track_fmt, rtsp->psz_path,
206               num );
207     msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf );
208     url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL );
209
210     if( url == NULL )
211     {
212         free( id );
213         return NULL;
214     }
215
216     httpd_UrlCatch( url, HTTPD_MSG_DESCRIBE, RtspCallbackId, (void *)id );
217     httpd_UrlCatch( url, HTTPD_MSG_SETUP,    RtspCallbackId, (void *)id );
218     httpd_UrlCatch( url, HTTPD_MSG_PLAY,     RtspCallbackId, (void *)id );
219     httpd_UrlCatch( url, HTTPD_MSG_PAUSE,    RtspCallbackId, (void *)id );
220     httpd_UrlCatch( url, HTTPD_MSG_GETPARAMETER, RtspCallbackId, (void *)id );
221     httpd_UrlCatch( url, HTTPD_MSG_TEARDOWN, RtspCallbackId, (void *)id );
222
223     return id;
224 }
225
226
227 void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t *id )
228 {
229     vlc_mutex_lock( &rtsp->lock );
230     for( int i = 0; i < rtsp->sessionc; i++ )
231     {
232         rtsp_session_t *ses = rtsp->sessionv[i];
233
234         for( int j = 0; j < ses->trackc; j++ )
235         {
236             if( ses->trackv[j].id == id->sout_id )
237             {
238                 rtsp_strack_t *tr = ses->trackv + j;
239                 net_Close( tr->fd );
240                 REMOVE_ELEM( ses->trackv, ses->trackc, j );
241             }
242         }
243     }
244
245     vlc_mutex_unlock( &rtsp->lock );
246     httpd_UrlDelete( id->url );
247     free( id );
248 }
249
250
251 /** rtsp must be locked */
252 static
253 rtsp_session_t *RtspClientNew( rtsp_stream_t *rtsp )
254 {
255     rtsp_session_t *s = malloc( sizeof( *s ) );
256     if( s == NULL )
257         return NULL;
258
259     s->stream = rtsp;
260     vlc_rand_bytes (&s->id, sizeof (s->id));
261     s->trackc = 0;
262     s->trackv = NULL;
263
264     TAB_APPEND( rtsp->sessionc, rtsp->sessionv, s );
265
266     return s;
267 }
268
269
270 /** rtsp must be locked */
271 static
272 rtsp_session_t *RtspClientGet( rtsp_stream_t *rtsp, const char *name )
273 {
274     char *end;
275     uint64_t id;
276     int i;
277
278     if( name == NULL )
279         return NULL;
280
281     errno = 0;
282     id = strtoull( name, &end, 0x10 );
283     if( errno || *end )
284         return NULL;
285
286     /* FIXME: use a hash/dictionary */
287     for( i = 0; i < rtsp->sessionc; i++ )
288     {
289         if( rtsp->sessionv[i]->id == id )
290             return rtsp->sessionv[i];
291     }
292     return NULL;
293 }
294
295
296 /** rtsp must be locked */
297 static
298 void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session )
299 {
300     int i;
301     TAB_REMOVE( rtsp->sessionc, rtsp->sessionv, session );
302
303     for( i = 0; i < session->trackc; i++ )
304         rtp_del_sink( session->trackv[i].id, session->trackv[i].fd );
305
306     free( session->trackv );
307     free( session );
308 }
309
310
311 /** Finds the next transport choice */
312 static inline const char *transport_next( const char *str )
313 {
314     /* Looks for comma */
315     str = strchr( str, ',' );
316     if( str == NULL )
317         return NULL; /* No more transport options */
318
319     str++; /* skips comma */
320     while( strchr( "\r\n\t ", *str ) )
321         str++;
322
323     return (*str) ? str : NULL;
324 }
325
326
327 /** Finds the next transport parameter */
328 static inline const char *parameter_next( const char *str )
329 {
330     while( strchr( ",;", *str ) == NULL )
331         str++;
332
333     return (*str == ';') ? (str + 1) : NULL;
334 }
335
336
337 /** RTSP requests handler
338  * @param id selected track for non-aggregate URLs,
339  *           NULL for aggregate URLs
340  */
341 static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
342                         httpd_client_t *cl,
343                         httpd_message_t *answer,
344                         const httpd_message_t *query )
345 {
346     sout_stream_t *p_stream = rtsp->owner;
347     char psz_sesbuf[17];
348     const char *psz_session = NULL, *psz;
349     char control[sizeof("rtsp://[]:12345") + NI_MAXNUMERICHOST
350                   + strlen( rtsp->psz_path )];
351     time_t now;
352
353     time (&now);
354
355     if( answer == NULL || query == NULL || cl == NULL )
356         return VLC_SUCCESS;
357     else
358     {
359         /* Build self-referential control URL */
360         char ip[NI_MAXNUMERICHOST], *ptr;
361
362         httpd_ServerIP( cl, ip );
363         ptr = strchr( ip, '%' );
364         if( ptr != NULL )
365             *ptr = '\0';
366
367         if( strchr( ip, ':' ) != NULL )
368             sprintf( control, "rtsp://[%s]:%u%s", ip, rtsp->port,
369                      rtsp->psz_path );
370         else
371             sprintf( control, "rtsp://%s:%u%s", ip, rtsp->port,
372                      rtsp->psz_path );
373     }
374
375     /* */
376     answer->i_proto = HTTPD_PROTO_RTSP;
377     answer->i_version= 0;
378     answer->i_type   = HTTPD_MSG_ANSWER;
379     answer->i_body = 0;
380     answer->p_body = NULL;
381
382     httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING );
383
384     /* Date: is always allowed, and sometimes mandatory with RTSP/2.0. */
385     struct tm ut;
386     if (gmtime_r (&now, &ut) != NULL)
387     {   /* RFC1123 format, GMT is mandatory */
388         static const char wdays[7][4] = {
389             "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
390         static const char mons[12][4] = {
391             "Jan", "Feb", "Mar", "Apr", "May", "Jun",
392             "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
393         httpd_MsgAdd (answer, "Date", "%s, %02u %s %04u %02u:%02u:%02u GMT",
394                       wdays[ut.tm_wday], ut.tm_mday, mons[ut.tm_mon],
395                       1900 + ut.tm_year, ut.tm_hour, ut.tm_min, ut.tm_sec);
396     }
397
398     if( query->i_proto != HTTPD_PROTO_RTSP )
399     {
400         answer->i_status = 505;
401     }
402     else
403     if( httpd_MsgGet( query, "Require" ) != NULL )
404     {
405         answer->i_status = 551;
406         httpd_MsgAdd( answer, "Unsupported", "%s",
407                       httpd_MsgGet( query, "Require" ) );
408     }
409     else
410     switch( query->i_type )
411     {
412         case HTTPD_MSG_DESCRIBE:
413         {   /* Aggregate-only */
414             if( id != NULL )
415             {
416                 answer->i_status = 460;
417                 break;
418             }
419
420             answer->i_status = 200;
421             httpd_MsgAdd( answer, "Content-Type",  "%s", "application/sdp" );
422             httpd_MsgAdd( answer, "Content-Base",  "%s", control );
423             answer->p_body = (uint8_t *)SDPGenerate( rtsp->owner, control );
424             if( answer->p_body != NULL )
425                 answer->i_body = strlen( (char *)answer->p_body );
426             else
427                 answer->i_status = 500;
428             break;
429         }
430
431         case HTTPD_MSG_SETUP:
432             /* Non-aggregate-only */
433             if( id == NULL )
434             {
435                 answer->i_status = 459;
436                 break;
437             }
438
439             psz_session = httpd_MsgGet( query, "Session" );
440             answer->i_status = 461;
441
442             for( const char *tpt = httpd_MsgGet( query, "Transport" );
443                  tpt != NULL;
444                  tpt = transport_next( tpt ) )
445             {
446                 bool b_multicast = true, b_unsupp = false;
447                 unsigned loport = 5004, hiport = 5005; /* from RFC3551 */
448
449                 /* Check transport protocol. */
450                 /* Currently, we only support RTP/AVP over UDP */
451                 if( strncmp( tpt, "RTP/AVP", 7 ) )
452                     continue;
453                 tpt += 7;
454                 if( strncmp( tpt, "/UDP", 4 ) == 0 )
455                     tpt += 4;
456                 if( strchr( ";,", *tpt ) == NULL )
457                     continue;
458
459                 /* Parse transport options */
460                 for( const char *opt = parameter_next( tpt );
461                      opt != NULL;
462                      opt = parameter_next( opt ) )
463                 {
464                     if( strncmp( opt, "multicast", 9 ) == 0)
465                         b_multicast = true;
466                     else
467                     if( strncmp( opt, "unicast", 7 ) == 0 )
468                         b_multicast = false;
469                     else
470                     if( sscanf( opt, "client_port=%u-%u", &loport, &hiport )
471                                 == 2 )
472                         ;
473                     else
474                     if( strncmp( opt, "mode=", 5 ) == 0 )
475                     {
476                         if( strncasecmp( opt + 5, "play", 4 )
477                          && strncasecmp( opt + 5, "\"PLAY\"", 6 ) )
478                         {
479                             /* Not playing?! */
480                             b_unsupp = true;
481                             break;
482                         }
483                     }
484                     else
485                     if( strncmp( opt,"destination=", 12 ) == 0 )
486                     {
487                         answer->i_status = 403;
488                         b_unsupp = true;
489                     }
490                     else
491                     {
492                     /*
493                      * Every other option is unsupported:
494                      *
495                      * "source" and "append" are invalid (server-only);
496                      * "ssrc" also (as clarified per RFC2326bis).
497                      *
498                      * For multicast, "port", "layers", "ttl" are set by the
499                      * stream output configuration.
500                      *
501                      * For unicast, we want to decide "server_port" values.
502                      *
503                      * "interleaved" is not implemented.
504                      */
505                         b_unsupp = true;
506                         break;
507                     }
508                 }
509
510                 if( b_unsupp )
511                     continue;
512
513                 if( b_multicast )
514                 {
515                     const char *dst = id->dst;
516                     if( dst == NULL )
517                         continue;
518
519                     if( psz_session == NULL )
520                     {
521                         /* Create a dummy session ID */
522                         snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%d",
523                                   rand() );
524                         psz_session = psz_sesbuf;
525                     }
526                     answer->i_status = 200;
527
528                     httpd_MsgAdd( answer, "Transport",
529                                   "RTP/AVP/UDP;destination=%s;port=%u-%u;"
530                                   "ttl=%d;mode=play",
531                                   dst, id->loport, id->hiport,
532                                   ( id->ttl > 0 ) ? id->ttl : 1 );
533                 }
534                 else
535                 {
536                     char ip[NI_MAXNUMERICHOST], src[NI_MAXNUMERICHOST];
537                     rtsp_session_t *ses = NULL;
538                     rtsp_strack_t track = { id->sout_id, -1, false };
539                     int sport;
540
541                     if( httpd_ClientIP( cl, ip ) == NULL )
542                     {
543                         answer->i_status = 500;
544                         continue;
545                     }
546
547                     track.fd = net_ConnectDgram( p_stream, ip, loport, -1,
548                                                  IPPROTO_UDP );
549                     if( track.fd == -1 )
550                     {
551                         msg_Err( p_stream,
552                                  "cannot create RTP socket for %s port %u",
553                                  ip, loport );
554                         answer->i_status = 500;
555                         continue;
556                     }
557
558                     net_GetSockAddress( track.fd, src, &sport );
559
560                     vlc_mutex_lock( &rtsp->lock );
561                     if( psz_session == NULL )
562                     {
563                         ses = RtspClientNew( rtsp );
564                         snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%"PRIx64,
565                                   ses->id );
566                         psz_session = psz_sesbuf;
567                     }
568                     else
569                     {
570                         /* FIXME: we probably need to remove an access out,
571                          * if there is already one for the same ID */
572                         ses = RtspClientGet( rtsp, psz_session );
573                         if( ses == NULL )
574                         {
575                             answer->i_status = 454;
576                             vlc_mutex_unlock( &rtsp->lock );
577                             continue;
578                         }
579                     }
580
581                     INSERT_ELEM( ses->trackv, ses->trackc, ses->trackc,
582                                  track );
583                     vlc_mutex_unlock( &rtsp->lock );
584
585                     httpd_ServerIP( cl, ip );
586
587                     if( strcmp( src, ip ) )
588                     {
589                         /* Specify source IP if it is different from the RTSP
590                          * control connection server address */
591                         char *ptr = strchr( src, '%' );
592                         if( ptr != NULL ) *ptr = '\0'; /* remove scope ID */
593
594                         httpd_MsgAdd( answer, "Transport",
595                                       "RTP/AVP/UDP;unicast;source=%s;"
596                                       "client_port=%u-%u;server_port=%u-%u;"
597                                       "ssrc=%08X;mode=play",
598                                       src, loport, loport + 1, sport,
599                                       sport + 1, id->ssrc );
600                     }
601                     else
602                     {
603                         httpd_MsgAdd( answer, "Transport",
604                                       "RTP/AVP/UDP;unicast;"
605                                       "client_port=%u-%u;server_port=%u-%u;"
606                                       "ssrc=%08X;mode=play",
607                                       loport, loport + 1, sport, sport + 1,
608                                       id->ssrc );
609                     }
610
611                     answer->i_status = 200;
612                 }
613                 break;
614             }
615             break;
616
617         case HTTPD_MSG_PLAY:
618         {
619             rtsp_session_t *ses;
620             answer->i_status = 200;
621
622             psz_session = httpd_MsgGet( query, "Session" );
623             const char *range = httpd_MsgGet (query, "Range");
624             if (range && strncmp (range, "npt=", 4))
625             {
626                 answer->i_status = 501;
627                 break;
628             }
629
630             vlc_mutex_lock( &rtsp->lock );
631             ses = RtspClientGet( rtsp, psz_session );
632             if( ses != NULL )
633             {
634                 /* FIXME: we really need to limit the number of tracks... */
635                 char info[ses->trackc * ( strlen( control )
636                                   + sizeof("/trackID=123;seq=65535, ") ) + 1];
637                 size_t infolen = 0;
638
639                 for( int i = 0; i < ses->trackc; i++ )
640                 {
641                     rtsp_strack_t *tr = ses->trackv + i;
642                     if( ( id == NULL ) || ( tr->id == id->sout_id ) )
643                     {
644                         if( !tr->playing )
645                         {
646                             tr->playing = true;
647                             rtp_add_sink( tr->id, tr->fd, false );
648                         }
649                         infolen += sprintf( info + infolen,
650                                             "%s/trackID=%u;seq=%u, ", control,
651                                             rtp_get_num( tr->id ),
652                                             rtp_get_seq( tr->id ) );
653                     }
654                 }
655                 if( infolen > 0 )
656                 {
657                     info[infolen - 2] = '\0'; /* remove trailing ", " */
658                     httpd_MsgAdd( answer, "RTP-Info", "%s", info );
659                 }
660             }
661             vlc_mutex_unlock( &rtsp->lock );
662
663             if( httpd_MsgGet( query, "Scale" ) != NULL )
664                 httpd_MsgAdd( answer, "Scale", "1." );
665             break;
666         }
667
668         case HTTPD_MSG_PAUSE:
669             answer->i_status = 405;
670             httpd_MsgAdd( answer, "Allow",
671                           "%s, TEARDOWN, PLAY, GET_PARAMETER",
672                           ( id != NULL ) ? "SETUP" : "DESCRIBE" );
673             break;
674
675         case HTTPD_MSG_GETPARAMETER:
676             if( query->i_body > 0 )
677             {
678                 answer->i_status = 451;
679                 break;
680             }
681
682             psz_session = httpd_MsgGet( query, "Session" );
683             answer->i_status = 200;
684             break;
685
686         case HTTPD_MSG_TEARDOWN:
687         {
688             rtsp_session_t *ses;
689
690             answer->i_status = 200;
691
692             psz_session = httpd_MsgGet( query, "Session" );
693
694             vlc_mutex_lock( &rtsp->lock );
695             ses = RtspClientGet( rtsp, psz_session );
696             if( ses != NULL )
697             {
698                 if( id == NULL ) /* Delete the entire session */
699                     RtspClientDel( rtsp, ses );
700                 else /* Delete one track from the session */
701                 for( int i = 0; i < ses->trackc; i++ )
702                 {
703                     if( ses->trackv[i].id == id->sout_id )
704                     {
705                         rtp_del_sink( id->sout_id, ses->trackv[i].fd );
706                         REMOVE_ELEM( ses->trackv, ses->trackc, i );
707                     }
708                 }
709             }
710             vlc_mutex_unlock( &rtsp->lock );
711             break;
712         }
713
714         default:
715             return VLC_EGENERIC;
716     }
717
718     if( psz_session )
719         httpd_MsgAdd( answer, "Session", "%s"/*;timeout=5*/, psz_session );
720
721     httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
722     httpd_MsgAdd( answer, "Cache-Control", "no-cache" );
723
724     psz = httpd_MsgGet( query, "Cseq" );
725     if( psz != NULL )
726         httpd_MsgAdd( answer, "Cseq", "%s", psz );
727     psz = httpd_MsgGet( query, "Timestamp" );
728     if( psz != NULL )
729         httpd_MsgAdd( answer, "Timestamp", "%s", psz );
730
731     return VLC_SUCCESS;
732 }
733
734
735 /** Aggregate RTSP callback */
736 static int RtspCallback( httpd_callback_sys_t *p_args,
737                          httpd_client_t *cl,
738                          httpd_message_t *answer,
739                          const httpd_message_t *query )
740 {
741     return RtspHandler( (rtsp_stream_t *)p_args, NULL, cl, answer, query );
742 }
743
744
745 /** Non-aggregate RTSP callback */
746 static int RtspCallbackId( httpd_callback_sys_t *p_args,
747                            httpd_client_t *cl,
748                            httpd_message_t *answer,
749                            const httpd_message_t *query )
750 {
751     rtsp_stream_id_t *id = (rtsp_stream_id_t *)p_args;
752     return RtspHandler( id->stream, id, cl, answer, query );
753 }