]> git.sesse.net Git - vlc/blobdiff - modules/misc/rtsp.c
- Add httpd_ServerIP() to obtain HTTP server's IP used with a given client
[vlc] / modules / misc / rtsp.c
index 0ca3a329e6be44668db314a58fffa1f1f7f60014..8bbfaa8d0fbf721af6180130a5411468b19c0681 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * rtsp.c: rtsp VoD server module
  *****************************************************************************
- * Copyright (C) 2003-2004 VideoLAN (Centrale Réseaux) and its contributors
+ * Copyright (C) 2003-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
@@ -46,8 +46,8 @@ static void Close( vlc_object_t * );
 #define HOST_TEXT N_( "Host address" )
 #define HOST_LONGTEXT N_( \
     "You can set the address, port and path the rtsp interface will bind to." \
-    "\n Syntax is address:port/path. Default is to bind to localhost address "\
-    "on port 554, with no path. Use 0.0.0.0 to bind to all addresses." )
+    "\n Syntax is address:port/path. Default is to bind to any address "\
+    "on port 554, with no path." )
 vlc_module_begin();
     set_shortname( _("RTSP VoD" ) );
     set_description( _("RTSP VoD server") );
@@ -114,7 +114,6 @@ struct vod_media_t
     char         *psz_rtsp_control;
     char         *psz_rtsp_path;
 
-    char *psz_destination;
     int  i_port;
     int  i_port_audio;
     int  i_port_video;
@@ -172,7 +171,7 @@ static int RtspCallback( httpd_callback_sys_t *, httpd_client_t *,
 static int RtspCallbackES( httpd_callback_sys_t *, httpd_client_t *,
                            httpd_message_t *, httpd_message_t * );
 
-static char *SDPGenerate( vod_media_t *, char * );
+static char *SDPGenerate( const vod_media_t *, httpd_client_t *cl );
 
 static void sprintf_hexa( char *s, uint8_t *p_data, int i_data )
 {
@@ -201,11 +200,6 @@ static int Open( vlc_object_t *p_this )
     vlc_UrlParse( &url, psz_url, 0 );
     if( psz_url ) free( psz_url );
 
-    if( !url.psz_host || !*url.psz_host )
-    {
-        if( url.psz_host ) free( url.psz_host );
-        url.psz_host = strdup( "localhost" );
-    }
     if( url.i_port <= 0 ) url.i_port = 554;
 
     p_vod->p_sys = p_sys = malloc( sizeof( vod_sys_t ) );
@@ -276,8 +270,8 @@ static vod_media_t *MediaNew( vod_t *p_vod, char *psz_name,
 
     asprintf( &p_media->psz_rtsp_path, "%s%s", p_sys->psz_path, psz_name );
     p_media->p_rtsp_url =
-        httpd_UrlNewUnique( p_sys->p_rtsp_host, p_media->psz_rtsp_path, 0, 0,
-                            NULL, 0 );
+        httpd_UrlNewUnique( p_sys->p_rtsp_host, p_media->psz_rtsp_path, NULL,
+                            NULL, NULL );
 
     if( !p_media->p_rtsp_url )
     {
@@ -465,8 +459,8 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
     }
 
     p_es->p_rtsp_url =
-        httpd_UrlNewUnique( p_vod->p_sys->p_rtsp_host, psz_urlc, 0, 0, NULL,
-                            0 );
+        httpd_UrlNewUnique( p_vod->p_sys->p_rtsp_host, psz_urlc, NULL, NULL,
+                            NULL );
 
     if( !p_es->p_rtsp_url )
     {
@@ -613,7 +607,6 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
 {
     vod_media_t *p_media = (vod_media_t*)p_args;
     vod_t *p_vod = p_media->p_vod;
-    char *psz_destination = p_media->psz_destination;
     char *psz_session = NULL;
     rtsp_client_t *p_rtsp;
 
@@ -630,21 +623,20 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
         case HTTPD_MSG_DESCRIBE:
         {
             char *psz_sdp =
-                SDPGenerate( p_media, psz_destination ?
-                             psz_destination : "0.0.0.0" );
+                SDPGenerate( p_media, cl );
 
             answer->i_status = 200;
             answer->psz_status = strdup( "OK" );
             httpd_MsgAdd( answer, "Content-type",  "%s", "application/sdp" );
 
-            answer->p_body = psz_sdp;
+            answer->p_body = (uint8_t *)psz_sdp;
             answer->i_body = strlen( psz_sdp );
             break;
         }
 
         case HTTPD_MSG_PLAY:
         {
-            char *psz_output, *ip;
+            char *psz_output, ip[NI_MAXNUMERICHOST];
             int i, i_port_audio = 0, i_port_video = 0;
 
             /* for now only multicast so easy */
@@ -668,7 +660,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
             }
             else if( p_rtsp->b_playing ) break;
 
-            if( !(ip = httpd_ClientIP( cl )) ) break;
+            if( httpd_ClientIP( cl, ip ) == NULL ) break;
 
             p_rtsp->b_playing = VLC_TRUE;
 
@@ -695,7 +687,6 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
             vod_MediaControl( p_vod, p_media, psz_session, VOD_MEDIA_PLAY,
                               psz_output );
             free( psz_output );
-            free( ip );
             break;
         }
 
@@ -776,37 +767,18 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
         psz_transport = httpd_MsgGet( query, "Transport" );
         fprintf( stderr, "HTTPD_MSG_SETUP: transport=%s\n", psz_transport );
 
-        if( strstr( psz_transport, "multicast" ) && p_media->psz_destination )
-        {
-            fprintf( stderr, "HTTPD_MSG_SETUP: multicast\n" );
-            answer->i_status = 200;
-            answer->psz_status = strdup( "OK" );
-            answer->i_body = 0;
-            answer->p_body = NULL;
-
-            psz_session = httpd_MsgGet( query, "Session" );
-            if( !psz_session || !*psz_session )
-            {
-                asprintf( &psz_session, "%d", rand() );
-            }
-
-            httpd_MsgAdd( answer, "Transport",
-                          "RTP/AVP/UDP;destination=%s;port=%d-%d;ttl=%d",
-                          p_media->psz_destination, p_media->i_port,
-                          p_media->i_port+1, p_media->i_ttl );
-        }
-        else if( strstr( psz_transport, "unicast" ) &&
-                 strstr( psz_transport, "client_port=" ) )
+        if( strstr( psz_transport, "unicast" ) &&
+            strstr( psz_transport, "client_port=" ) )
         {
             rtsp_client_t *p_rtsp;
             rtsp_client_es_t *p_rtsp_es;
-            char *ip = httpd_ClientIP( cl );
+            char ip[NI_MAXNUMERICHOST];
             int i_port = atoi( strstr( psz_transport, "client_port=" ) +
                                strlen("client_port=") );
 
-            if( !ip )
+            if( httpd_ClientIP( cl, ip ) == NULL )
             {
-                answer->i_status = 400;
+                answer->i_status = 500;
                 answer->psz_status = strdup( "Internal server error" );
                 answer->i_body = 0;
                 answer->p_body = NULL;
@@ -828,7 +800,7 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
                 if( !p_rtsp )
                 {
                     /* FIXME right error code */
-                    answer->i_status = 400;
+                    answer->i_status = 454;
                     answer->psz_status = strdup( "Unknown session id" );
                     answer->i_body = 0;
                     answer->p_body = NULL;
@@ -853,8 +825,8 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
         }
         else /* TODO  strstr( psz_transport, "interleaved" ) ) */
         {
-            answer->i_status = 400;
-            answer->psz_status = strdup( "Bad Request" );
+            answer->i_status = 461;
+            answer->psz_status = strdup( "Unsupported Transport" );
             answer->i_body = 0;
             answer->p_body = NULL;
         }
@@ -962,10 +934,10 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
  * SDPGenerate: TODO
  * FIXME: need to be moved to a common place ?
  *****************************************************************************/
-static char *SDPGenerate( vod_media_t *p_media, char *psz_destination )
+static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
 {
     int i, i_size;
-    char *p, *psz_sdp;
+    char *p, *psz_sdp, *ip;
 
     /* Calculate size */
     i_size = strlen( "v=0\r\n" ) +
@@ -976,8 +948,7 @@ static char *SDPGenerate( vod_media_t *p_media, char *psz_destination )
         strlen( "e=*\r\n" ) + strlen( p_media->psz_session_email ) +
         strlen( "t=0 0\r\n" ) + /* FIXME */
         strlen( "a=tool:"PACKAGE_STRING"\r\n" ) +
-        strlen( "c=IN IP4 */*\r\n" ) + 20 + 10 +
-        strlen( psz_destination ? psz_destination : "0.0.0.0" ) +
+        strlen( "c=IN IPn */*\r\n" ) + 20 + 10 + NI_MAXNUMERICHOST +
         strlen( "a=range:npt=0-1000000000.000\r\n" );
 
     for( i = 0; i < p_media->i_es; i++ )
@@ -1016,8 +987,7 @@ static char *SDPGenerate( vod_media_t *p_media, char *psz_destination )
     p += sprintf( p, "t=0 0\r\n" ); /* FIXME */
     p += sprintf( p, "a=tool:"PACKAGE_STRING"\r\n" );
 
-    p += sprintf( p, "c=IN IP4 %s/%d\r\n", psz_destination ?
-                  psz_destination : "0.0.0.0", p_media->i_ttl );
+    p += sprintf( p, "c=IN IP4 0.0.0.0\r\n" );
 
     if( p_media->i_length > 0 )
     p += sprintf( p, "a=range:npt=0-%.3f\r\n",