]> git.sesse.net Git - vlc/blobdiff - modules/access/mms/mmsh.c
ignore mvn generated files
[vlc] / modules / access / mms / mmsh.c
index 99cf27a68f32a58dd60b49ca73b21acbbd0912d9..cc22555931ff76a3f9b6a0538a2f50784e5f11bd 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#define _GNU_SOURCE
-#include <stdlib.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
 #include <vlc_access.h>
@@ -50,8 +52,8 @@
 int  E_(MMSHOpen)  ( access_t * );
 void E_(MMSHClose) ( access_t * );
 
-static int  Read( access_t *, uint8_t *, int );
-static int  ReadRedirect( access_t *, uint8_t *, int );
+static ssize_t Read( access_t *, uint8_t *, size_t );
+static ssize_t ReadRedirect( access_t *, uint8_t *, size_t );
 static int  Seek( access_t *, int64_t );
 static int  Control( access_t *, int, va_list );
 
@@ -90,7 +92,11 @@ int E_(MMSHOpen)( access_t *p_access )
     p_access->info.b_eof = VLC_FALSE;
     p_access->info.i_title = 0;
     p_access->info.i_seekpoint = 0;
+
     p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
+
     memset( p_sys, 0, sizeof( access_sys_t ) );
     p_sys->i_proto= MMS_PROTO_HTTP;
     p_sys->fd     = -1;
@@ -117,6 +123,7 @@ int E_(MMSHOpen)( access_t *p_access )
             free( psz_http_proxy );
         }
     }
+
     if( *psz_proxy )
     {
         p_sys->b_proxy = VLC_TRUE;
@@ -137,13 +144,15 @@ int E_(MMSHOpen)( access_t *p_access )
 
     if( p_sys->b_proxy )
     {
-       if( p_sys->proxy.psz_host == NULL || *p_sys->proxy.psz_host == '\0' )
+        if( ( p_sys->proxy.psz_host == NULL ) ||
+            ( *p_sys->proxy.psz_host == '\0' ) )
         {
             msg_Warn( p_access, "invalid proxy host" );
             vlc_UrlClean( &p_sys->proxy );
             free( p_sys );
             return VLC_EGENERIC;
         }
+
         if( p_sys->proxy.i_port <= 0 )
             p_sys->proxy.i_port = 80;
         msg_Dbg( p_access, "Using http proxy %s:%d",
@@ -152,7 +161,8 @@ int E_(MMSHOpen)( access_t *p_access )
 
     /* open a tcp connection */
     vlc_UrlParse( &p_sys->url, p_access->psz_path, 0 );
-    if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' )
+    if( ( p_sys->url.psz_host == NULL ) ||
+        ( *p_sys->url.psz_host == '\0' ) )
     {
         msg_Err( p_access, "invalid host" );
         vlc_UrlClean( &p_sys->proxy );
@@ -216,8 +226,7 @@ void E_( MMSHClose )( access_t *p_access )
 
     Stop( p_access );
 
-    if( p_sys->p_header )
-        free( p_sys->p_header  );
+    free( p_sys->p_header  );
 
     vlc_UrlClean( &p_sys->proxy );
     vlc_UrlClean( &p_sys->url );
@@ -251,11 +260,6 @@ static int Control( access_t *p_access, int i_query, va_list args )
 
         case ACCESS_CAN_CONTROL_PACE:
             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
-
-#if 0       /* Disable for now until we have a clock synchro algo
-             * which works with something else than MPEG over UDP */
-            *pb_bool = VLC_FALSE;
-#endif
             *pb_bool = VLC_TRUE;
             break;
 
@@ -274,7 +278,7 @@ static int Control( access_t *p_access, int i_query, va_list args )
             i_int = (int)va_arg( args, int );
             pb_bool = (vlc_bool_t *)va_arg( args, vlc_bool_t * );
 
-            if( i_int < 0 || i_int > 127 )
+            if( (i_int < 0) || (i_int > 127) )
                 return VLC_EGENERIC;
             *pb_bool =  p_sys->asfh.stream[i_int].i_selected ? VLC_TRUE : VLC_FALSE;
             break;
@@ -285,6 +289,7 @@ static int Control( access_t *p_access, int i_query, va_list args )
         case ACCESS_SET_TITLE:
         case ACCESS_SET_SEEKPOINT:
         case ACCESS_SET_PRIVATE_ID_STATE:
+        case ACCESS_GET_CONTENT_TYPE:
             return VLC_EGENERIC;
 
         default:
@@ -315,6 +320,7 @@ static int Seek( access_t *p_access, int64_t i_pos )
 
     while( !p_access->b_die )
     {
+        msg_Warn( p_access, "GetPacket 1" );
         if( GetPacket( p_access, &ck ) )
             break;
 
@@ -335,7 +341,7 @@ static int Seek( access_t *p_access, int64_t i_pos )
 /*****************************************************************************
  * Read:
  *****************************************************************************/
-static int ReadRedirect( access_t *p_access, uint8_t *p, int i_len )
+static ssize_t ReadRedirect( access_t *p_access, uint8_t *p, size_t i_len )
 {
     return 0;
 }
@@ -343,7 +349,7 @@ static int ReadRedirect( access_t *p_access, uint8_t *p, int i_len )
 /*****************************************************************************
  * Read:
  *****************************************************************************/
-static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
+static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
 {
     access_sys_t *p_sys = p_access->p_sys;
     size_t       i_copy;
@@ -354,10 +360,11 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
 
     while( i_data < (size_t) i_len )
     {
-        if( p_access->info.i_pos < p_sys->i_start + p_sys->i_header )
+        if( p_access->info.i_pos < (p_sys->i_start + p_sys->i_header) )
         {
             int i_offset = p_access->info.i_pos - p_sys->i_start;
-            i_copy = __MIN( p_sys->i_header - i_offset, (int)((size_t)i_len - i_data) );
+            i_copy = __MIN( p_sys->i_header - i_offset,
+                            (int)((size_t)i_len - i_data) );
             memcpy( &p_buffer[i_data], &p_sys->p_header[i_offset], i_copy );
 
             i_data += i_copy;
@@ -367,7 +374,6 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
         {
             i_copy = __MIN( p_sys->i_packet_length - p_sys->i_packet_used,
                             i_len - i_data );
-
             memcpy( &p_buffer[i_data],
                     &p_sys->p_packet[p_sys->i_packet_used],
                     i_copy );
@@ -381,7 +387,6 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
         {
             i_copy = __MIN( p_sys->asfh.i_min_data_packet_size - p_sys->i_packet_used,
                             i_len - i_data );
-
             memset( &p_buffer[i_data], 0, i_copy );
 
             i_data += i_copy;
@@ -391,12 +396,13 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
         else
         {
             chunk_t ck;
+        msg_Warn( p_access, "GetPacket 2" );
             if( GetPacket( p_access, &ck ) )
             {
                 int i_ret = -1;
                 if( p_sys->b_broadcast )
                 {
-                    if( ck.i_type == 0x4524 && ck.i_sequence != 0 )
+                    if( (ck.i_type == 0x4524) && (ck.i_sequence != 0) )
                         i_ret = Restart( p_access );
                     else if( ck.i_type == 0x4324 )
                         i_ret = Reset( p_access );
@@ -436,15 +442,15 @@ static int Restart( access_t *p_access )
     if( Describe( p_access, &psz_location ) )
     {
         msg_Err( p_access, "describe failed" );
-        return -1;
+        return VLC_EGENERIC;
     }
     /* */
     if( Start( p_access, 0 ) )
     {
         msg_Err( p_access, "Start failed" );
-        return -1;
+        return VLC_EGENERIC;
     }
-    return 0;
+    return VLC_SUCCESS;
 }
 static int Reset( access_t *p_access )
 {
@@ -464,7 +470,7 @@ static int Reset( access_t *p_access )
     /* Get the next header FIXME memory loss ? */
     GetHeader( p_access );
     if( p_sys->i_header <= 0 )
-        return -1;
+        return VLC_EGENERIC;
 
     E_( asf_HeaderParse )( &p_sys->asfh,
                            p_sys->p_header, p_sys->i_header );
@@ -496,7 +502,7 @@ static int Reset( access_t *p_access )
     /* */
     p_sys->i_packet_used = 0;
     p_sys->i_packet_length = 0;
-    return 0;
+    return VLC_SUCCESS;
 }
 
 static int OpenConnection( access_t *p_access )
@@ -517,7 +523,9 @@ static int OpenConnection( access_t *p_access )
         net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
                     "GET http://%s:%d%s HTTP/1.0\r\n",
                     p_sys->url.psz_host, p_sys->url.i_port,
-                    ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path );
+                    ( (p_sys->url.psz_path == NULL) ||
+                      (*p_sys->url.psz_path == '\0') ) ?
+                         "/" : p_sys->url.psz_path );
 
         /* Proxy Authentication */
         if( p_sys->proxy.psz_username && *p_sys->proxy.psz_username )
@@ -541,7 +549,9 @@ static int OpenConnection( access_t *p_access )
         net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
                     "GET %s HTTP/1.0\r\n"
                     "Host: %s:%d\r\n",
-                    ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path,
+                    ( (p_sys->url.psz_path == NULL) ||
+                      (*p_sys->url.psz_path == '\0') ) ?
+                            "/" : p_sys->url.psz_path,
                     p_sys->url.psz_host, p_sys->url.i_port );
     }
     return VLC_SUCCESS;
@@ -566,7 +576,8 @@ static int Describe( access_t  *p_access, char **ppsz_location )
     p_sys->p_packet = NULL;
     E_( GenerateGuid )( &p_sys->guid );
 
-    OpenConnection( p_access );
+    if( OpenConnection( p_access ) )
+        return VLC_EGENERIC;
 
     net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
                 "Accept: */*\r\n"
@@ -589,6 +600,7 @@ static int Describe( access_t  *p_access, char **ppsz_location )
         msg_Err( p_access, "failed to read answer" );
         goto error;
     }
+
     if( strncmp( psz, "HTTP/1.", 7 ) )
     {
         msg_Err( p_access, "invalid HTTP reply '%s'", psz );
@@ -664,8 +676,8 @@ static int Describe( access_t  *p_access, char **ppsz_location )
     }
 
     /* Handle the redirection */
-    if( ( i_code == 301 || i_code == 302 ||
-          i_code == 303 || i_code == 307 ) &&
+    if( ( (i_code == 301) || (i_code == 302) ||
+          (i_code == 303) || (i_code == 307) ) &&
         psz_location && *psz_location )
     {
         msg_Dbg( p_access, "redirection to %s", psz_location );
@@ -683,7 +695,8 @@ static int Describe( access_t  *p_access, char **ppsz_location )
         goto error;
     }
     /* close this connection */
-    net_Close( p_sys->fd ); p_sys->fd = -1;
+    net_Close( p_sys->fd );
+    p_sys->fd = -1;
 
     /* *** parse header and get stream and their id *** */
     /* get all streams properties,
@@ -711,14 +724,14 @@ error:
     }
     return VLC_EGENERIC;
 }
+
 static void GetHeader( access_t *p_access )
 {
     access_sys_t *p_sys = p_access->p_sys;
 
     /* Read the asf header */
     p_sys->i_header = 0;
-    if( p_sys->p_header )
-        free( p_sys->p_header  );
+    free( p_sys->p_header  );
     p_sys->p_header = NULL;
     for( ;; )
     {
@@ -739,15 +752,15 @@ static void GetHeader( access_t *p_access )
 
 
 /*****************************************************************************
- *
- *****************************************************************************/
-static int Start( access_t *p_access, off_t i_pos )
+ * Start stream
+ ****************************************************************************/
+static int Start( access_t *p_access, int64_t i_pos )
 {
     access_sys_t *p_sys = p_access->p_sys;
     int  i_streams = 0;
     int  i_streams_selected = 0;
     int  i;
-    char *psz;
+    char *psz = NULL;
 
     msg_Dbg( p_access, "starting stream" );
 
@@ -765,7 +778,8 @@ static int Start( access_t *p_access, off_t i_pos )
         return VLC_EGENERIC;
     }
 
-    OpenConnection( p_access );
+    if( OpenConnection( p_access ) )
+        return VLC_EGENERIC;
 
     net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
                 "Accept: */*\r\n"
@@ -801,7 +815,6 @@ static int Start( access_t *p_access, off_t i_pos )
             {
                 i_select = 0;
             }
-
             net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
                         "ffff:%d:%d ", i, i_select );
         }
@@ -816,11 +829,13 @@ static int Start( access_t *p_access, off_t i_pos )
         return VLC_EGENERIC;
     }
 
-    if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
+    psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
+    if( psz == NULL )
     {
-        msg_Err( p_access, "cannot read data" );
+        msg_Err( p_access, "cannot read data 0" );
         return VLC_EGENERIC;
     }
+
     if( atoi( &psz[9] ) >= 400 )
     {
         msg_Err( p_access, "error: %s", psz );
@@ -836,7 +851,7 @@ static int Start( access_t *p_access, off_t i_pos )
         char *psz = net_Gets( p_access, p_sys->fd, NULL );
         if( psz == NULL )
         {
-            msg_Err( p_access, "cannot read data" );
+            msg_Err( p_access, "cannot read data 1" );
             return VLC_EGENERIC;
         }
         if( *psz == '\0' )
@@ -855,7 +870,7 @@ static int Start( access_t *p_access, off_t i_pos )
 }
 
 /*****************************************************************************
- *
+ * closing stream
  *****************************************************************************/
 static void Stop( access_t *p_access )
 {
@@ -870,7 +885,7 @@ static void Stop( access_t *p_access )
 }
 
 /*****************************************************************************
- *
+ * get packet
  *****************************************************************************/
 static int GetPacket( access_t * p_access, chunk_t *p_ck )
 {
@@ -887,7 +902,10 @@ static int GetPacket( access_t * p_access, chunk_t *p_ck )
      * entire header.
      */
     if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer, 4, VLC_TRUE ) < 4 )
+    {
+       msg_Err( p_access, "cannot read data 2" );
        return VLC_EGENERIC;
+    }
 
     p_ck->i_type = GetWLE( p_sys->buffer);
     p_ck->i_size = GetWLE( p_sys->buffer + 2);
@@ -898,7 +916,7 @@ static int GetPacket( access_t * p_access, chunk_t *p_ck )
 
     if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer + 4, restsize, VLC_TRUE ) < restsize )
     {
-        msg_Err( p_access, "cannot read data" );
+        msg_Err( p_access, "cannot read data 3" );
         return VLC_EGENERIC;
     }
     p_ck->i_sequence  = GetDWLE( p_sys->buffer + 4);
@@ -945,7 +963,7 @@ static int GetPacket( access_t * p_access, chunk_t *p_ck )
         (net_Read( p_access, p_sys->fd, NULL, &p_sys->buffer[12],
                    p_ck->i_data, VLC_TRUE ) < p_ck->i_data) )
     {
-        msg_Err( p_access, "cannot read data" );
+        msg_Err( p_access, "cannot read data 4" );
         return VLC_EGENERIC;
     }