Changeset 6e5f468a1e77d3986e2bd8b9f0dd5fb2f5aaa964

Show
Ignore:
Timestamp:
30/08/07 23:36:40 (1 year ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1188509800 +0000
git-parent:

[1706407b93acb91819eedeb9557d67c6bbe23de4]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1188509800 +0000
Message:

Fix a bunch of bugs I added, and simplify some stuff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/stream_out/rtsp.c

    r4d9440e r6e5f468  
    22 * rtsp.c: RTSP support for RTP stream output module 
    33 ***************************************************************************** 
    4  * Copyright (C) 2003-2007 the VideoLAN team 
     4 * Copyright (C) 2003-2004 the VideoLAN team 
     5 * Copyright © 2007 Rémi Denis-Courmont 
     6 * 
    57 * $Id: rtp.c 21407 2007-08-22 20:10:41Z courmisch $ 
    68 * 
     
    3234#include <vlc_network.h> 
    3335#include <assert.h> 
     36#include <errno.h> 
     37#include <stdlib.h> 
    3438 
    3539#include "rtp.h" 
     
    5256 
    5357static int  RtspCallback( httpd_callback_sys_t *p_args, 
    54                           httpd_client_t *cl, 
    55                           httpd_message_t *answer, httpd_message_t *query ); 
     58                          httpd_client_t *cl, httpd_message_t *answer, 
     59                          const httpd_message_t *query ); 
    5660static int  RtspCallbackId( httpd_callback_sys_t *p_args, 
    57                             httpd_client_t *cl, 
    58                             httpd_message_t *answer, httpd_message_t *query ); 
     61                            httpd_client_t *cl, httpd_message_t *answer, 
     62                            const httpd_message_t *query ); 
    5963static void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session ); 
    6064 
     
    141145{ 
    142146    rtsp_stream_t *stream; 
     147    uint64_t       id; 
    143148 
    144149    /* output (id-access) */ 
    145150    int            trackc; 
    146151    rtsp_strack_t *trackv; 
    147  
    148     char name[0]; 
    149152}; 
    150153 
     
    230233/** rtsp must be locked */ 
    231234static 
    232 rtsp_session_t *RtspClientNew( rtsp_stream_t *rtsp, const char *name ) 
    233 
    234     rtsp_session_t *s = malloc( sizeof( *s ) + strlen( name ) + 1 ); 
     235rtsp_session_t *RtspClientNew( rtsp_stream_t *rtsp ) 
     236
     237    rtsp_session_t *s = malloc( sizeof( *s ) ); 
     238    if( s == NULL ) 
     239        return NULL; 
    235240 
    236241    s->stream = rtsp; 
     242    s->id = rand(); /* FIXME: not enough entropy */ 
    237243    s->trackc = 0; 
    238244    s->trackv = NULL; 
    239     strcpy( s->name, name ); 
    240245 
    241246    TAB_APPEND( rtsp->sessionc, rtsp->sessionv, s ); 
     
    249254rtsp_session_t *RtspClientGet( rtsp_stream_t *rtsp, const char *name ) 
    250255{ 
     256    char *end; 
     257    uint64_t id; 
    251258    int i; 
    252259 
     
    254261        return NULL; 
    255262 
     263    errno = 0; 
     264    id = strtoull( name, &end, 0x10 ); 
     265    if( errno || *end ) 
     266        return NULL; 
     267 
    256268    /* FIXME: use a hash/dictionary */ 
    257269    for( i = 0; i < rtsp->sessionc; i++ ) 
    258270    { 
    259         if( !strcmp( rtsp->sessionv[i]->name, name )
     271        if( rtsp->sessionv[i]->id == id
    260272            return rtsp->sessionv[i]; 
    261273    } 
     
    285297static int RtspCallback( httpd_callback_sys_t *p_args, 
    286298                         httpd_client_t *cl, 
    287                          httpd_message_t *answer, httpd_message_t *query ) 
     299                         httpd_message_t *answer, 
     300                         const httpd_message_t *query ) 
    288301{ 
    289302    rtsp_stream_t *rtsp = (rtsp_stream_t *)p_args; 
     
    305318    { 
    306319        answer->i_status = 551; 
    307         httpd_MsgAdd( query, "Unsupported", "%s", 
     320        httpd_MsgAdd( answer, "Unsupported", "%s", 
    308321                      httpd_MsgGet( query, "Require" ) ); 
    309322    } 
     
    433446static int RtspCallbackId( httpd_callback_sys_t *p_args, 
    434447                           httpd_client_t *cl, 
    435                            httpd_message_t *answer, httpd_message_t *query ) 
     448                           httpd_message_t *answer, 
     449                           const httpd_message_t *query ) 
    436450{ 
    437451    rtsp_stream_id_t *id = (rtsp_stream_id_t *)p_args; 
    438452    rtsp_stream_t    *rtsp = id->stream; 
    439453    sout_stream_t    *p_stream = id->stream->owner; 
    440     char psz_session_init[21]; 
     454    char psz_sesbuf[17]; 
    441455    const char *psz_session, *psz; 
    442456 
    443457    if( answer == NULL || query == NULL ) 
    444458        return VLC_SUCCESS; 
    445     //fprintf( stderr, "RtspCallback query: type=%d\n", query->i_type ); 
    446459 
    447460    /* */ 
     
    452465    answer->p_body = NULL; 
    453466 
    454     /* Create new session ID if needed */ 
    455467    psz_session = httpd_MsgGet( query, "Session" ); 
    456     if( psz_session == NULL ) 
    457     { 
    458         /* FIXME: should be somewhat secure randomness */ 
    459         snprintf( psz_session_init, sizeof(psz_session_init), I64Fu, 
    460                   NTPtime64() + rand() ); 
    461     } 
    462468 
    463469    if( httpd_MsgGet( query, "Require" ) != NULL ) 
    464470    { 
    465471        answer->i_status = 551; 
    466         httpd_MsgAdd( query, "Unsupported", "%s", 
     472        httpd_MsgAdd( answer, "Unsupported", "%s", 
    467473                      httpd_MsgGet( query, "Require" ) ); 
    468474    } 
     
    516522                    } 
    517523                    else 
     524                    if( strncmp( opt,"destination=", 12 ) == 0 ) 
     525                    { 
     526                        answer->i_status = 403; 
     527                        b_unsupp = VLC_TRUE; 
     528                    } 
     529                    else 
    518530                    { 
    519531                    /* 
    520532                     * Every other option is unsupported: 
    521533                     * 
    522                      * "source" and "append" are invalid. 
     534                     * "source" and "append" are invalid (server-only); 
     535                     * "ssrc" also (as clarified per RFC2326bis). 
    523536                     * 
    524537                     * For multicast, "port", "layers", "ttl" are set by the 
    525538                     * stream output configuration. 
    526539                     * 
    527                      * For unicast, we do not allow "destination" as it 
    528                      * carries a DoS risk, and we decide on "server_port". 
     540                     * For unicast, we want to decide "server_port" values. 
    529541                     * 
    530                      * "interleaved" and "ssrc" are not implemented. 
     542                     * "interleaved" is not implemented. 
    531543                     */ 
    532544                        b_unsupp = VLC_TRUE; 
     
    586598                    if( psz_session == NULL ) 
    587599                    { 
    588                         psz_session = psz_session_init; 
    589                         ses = RtspClientNew( rtsp, psz_session ); 
     600                        ses = RtspClientNew( rtsp ); 
     601                        snprintf( psz_sesbuf, sizeof( psz_sesbuf ), I64Fx, 
     602                                  ses->id ); 
     603                        psz_session = psz_sesbuf; 
    590604                    } 
    591605                    else