- case HTTPD_MSG_SETUP:
- {
- answer->i_status = 461;
-
- for( const char *tpt = httpd_MsgGet( query, "Transport" );
- tpt != NULL;
- tpt = transport_next( tpt ) )
- {
- vlc_bool_t b_multicast = VLC_TRUE, b_unsupp = VLC_FALSE;
- unsigned loport = 5004, hiport = 5005; /* from RFC3551 */
-
- /* Check transport protocol. */
- /* Currently, we only support RTP/AVP over UDP */
- if( strncmp( tpt, "RTP/AVP", 7 ) )
- continue;
- tpt += 7;
- if( strncmp( tpt, "/UDP", 4 ) == 0 )
- tpt += 4;
- if( strchr( ";,", *tpt ) == NULL )
- continue;
-
- /* Parse transport options */
- for( const char *opt = parameter_next( tpt );
- opt != NULL;
- opt = parameter_next( opt ) )
- {
- if( strncmp( opt, "multicast", 9 ) == 0)
- b_multicast = VLC_TRUE;
- else
- if( strncmp( opt, "unicast", 7 ) == 0 )
- b_multicast = VLC_FALSE;
- else
- if( sscanf( opt, "client_port=%u-%u", &loport, &hiport ) == 2 )
- ;
- else
- if( strncmp( opt, "mode=", 5 ) == 0 )
- {
- if( strncasecmp( opt + 5, "play", 4 )
- && strncasecmp( opt + 5, "\"PLAY\"", 6 ) )
- {
- /* Not playing?! */
- b_unsupp = VLC_TRUE;
- break;
- }
- }
- else
- {
- /*
- * Every other option is unsupported:
- *
- * "source" and "append" are invalid.
- *
- * For multicast, "port", "layers", "ttl" are set by the
- * stream output configuration.
- *
- * For unicast, we do not allow "destination" as it
- * carries a DoS risk, and we decide on "server_port".
- *
- * "interleaved" and "ssrc" are not implemented.
- */
- b_unsupp = VLC_TRUE;
- break;
- }
- }
-
- if( b_unsupp )
- continue;
-
- if( b_multicast )
- {
- if( id->psz_destination == NULL )
- continue;
-
- answer->i_status = 200;
-
- httpd_MsgAdd( answer, "Transport",
- "RTP/AVP/UDP;destination=%s;port=%d-%d;"
- "ttl=%d;mode=play",
- id->psz_destination, id->i_port, id->i_port+1,
- ( p_sys->i_ttl > 0 ) ? p_sys->i_ttl : 1 );
- }
- else
- {
- char ip[NI_MAXNUMERICHOST], psz_access[22],
- url[NI_MAXNUMERICHOST + 8];
- sout_access_out_t *p_access;
- rtsp_client_t *rtsp = NULL;
-
- if( ( hiport - loport ) > 1 )
- continue;
-
- if( psz_session == NULL )
- {
- psz_session = psz_session_init;
- rtsp = RtspClientNew( p_stream, psz_session );
- }
- else
- {
- /* FIXME: we probably need to remove an access out,
- * if there is already one for the same ID */
- rtsp = RtspClientGet( p_stream, psz_session );
- if( rtsp == NULL )
- {
- answer->i_status = 454;
- continue;
- }
- }
-
- if( httpd_ClientIP( cl, ip ) == NULL )
- {
- answer->i_status = 500;
- continue;
- }
-
- if( p_sys->i_ttl )
- snprintf( psz_access, sizeof( psz_access ),
- "udp{raw,rtcp,ttl=%d}", p_sys->i_ttl );
- else
- strcpy( psz_access, "udp{raw,rtcp}" );
-
- snprintf( url, sizeof( url ),
- ( strchr( ip, ':' ) != NULL ) ? "[%s]:%d" : "%s:%d",
- ip, loport );
-
- p_access = sout_AccessOutNew( p_stream->p_sout,
- psz_access, url );
- if( p_access == NULL )
- {
- msg_Err( p_stream,
- "cannot create access output for %s://%s",
- psz_access, url );
- answer->i_status = 500;
- break;
- }
-
- TAB_APPEND( rtsp->i_id, rtsp->id, id );
- TAB_APPEND( rtsp->i_access, rtsp->access, p_access );
-
- char *src = var_GetNonEmptyString (p_access, "src-addr");
- int sport = var_GetInteger (p_access, "src-port");
-
- httpd_ServerIP( cl, ip );
- fprintf( stderr, "src = %s, ip = %s\n", src, ip );
-
- if( ( src != NULL ) && strcmp( src, ip ) )
- {
- /* Specify source IP if it is different from the RTSP
- * control connection server address */
- httpd_MsgAdd( answer, "Transport",
- "RTP/AVP/UDP;unicast;source=%s;"
- "client_port=%u-%u;server_port=%u-%u;"
- "mode=play",
- src, loport, hiport, sport, sport + 1 );
- }
- else
- {
- httpd_MsgAdd( answer, "Transport",
- "RTP/AVP/UDP;unicast;"
- "client_port=%u-%u;server_port=%u-%u;"
- "mode=play",
- loport, hiport, sport, sport + 1 );
- }
-
- answer->i_status = 200;
- free( src );
- }
- break;
- }