]> git.sesse.net Git - vlc/blobdiff - modules/access/ftp.c
Qt4 - minwidth of dropdown inside settings dialogs, patch by André Weber
[vlc] / modules / access / ftp.c
index c54829a0b30e95378b0d490ca206ecf53c75dfad..cb7f639fdad6aff15dd7ffff0a826cf4c26f81d4 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
+#include <vlc/vlc.h>
+
 #include <assert.h>
 
-#include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <vlc_interaction.h>
+#include <vlc_access.h>
+#include <vlc_interface.h>
 
-#include "network.h"
+#include <vlc_network.h>
 #include "vlc_url.h"
-#include "stream_output.h"
+#include <vlc_sout.h>
+
+#ifndef IPPORT_FTP
+# define IPPORT_FTP 21u
+#endif
 
 /*****************************************************************************
  * Module descriptor
@@ -82,15 +86,14 @@ vlc_module_begin();
     set_capability( "sout access", 0 );
     set_category( CAT_SOUT );
     set_subcategory( SUBCAT_SOUT_ACO );
-    add_shortcut( "ftp" );
     set_callbacks( OutOpen, OutClose );
 vlc_module_end();
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int Read( access_t *, uint8_t *, int );
-static int Write( sout_access_out_t *, block_t * );
+static ssize_t Read( access_t *, uint8_t *, size_t );
+static ssize_t Write( sout_access_out_t *, block_t * );
 static int Seek( access_t *, int64_t );
 static int OutSeek( sout_access_out_t *, int64_t );
 static int Control( access_t *, int, va_list );
@@ -123,7 +126,7 @@ static int Login( vlc_object_t *p_access, access_sys_t *p_sys )
     if( fd == -1 )
     {
         msg_Err( p_access, "connection failed" );
-        intf_UserFatal( p_access, VLC_FALSE, _("Network interaction failed"), 
+        intf_UserFatal( p_access, VLC_FALSE, _("Network interaction failed"),
                         _("VLC could not connect with the given server.") );
         return -1;
     }
@@ -133,7 +136,7 @@ static int Login( vlc_object_t *p_access, access_sys_t *p_sys )
     if( i_answer / 100 != 2 )
     {
         msg_Err( p_access, "connection rejected" );
-        intf_UserFatal( p_access, VLC_FALSE, _("Network interaction failed"), 
+        intf_UserFatal( p_access, VLC_FALSE, _("Network interaction failed"),
                         _("VLC's connection to the given server was rejected.") );
         return -1;
     }
@@ -193,8 +196,8 @@ static int Login( vlc_object_t *p_access, access_sys_t *p_sys )
                     if( i_answer / 100 != 2 )
                     {
                         msg_Err( p_access, "account rejected" );
-                        intf_UserFatal( p_access, VLC_FALSE, 
-                                        _("Network interaction failed"), 
+                        intf_UserFatal( p_access, VLC_FALSE,
+                                        _("Network interaction failed"),
                                         _("Your account was rejected.") );
                         return -1;
                     }
@@ -203,17 +206,17 @@ static int Login( vlc_object_t *p_access, access_sys_t *p_sys )
 
                 default:
                     msg_Err( p_access, "password rejected" );
-                    intf_UserFatal( p_access, VLC_FALSE, 
-                                    _("Network interaction failed"), 
+                    intf_UserFatal( p_access, VLC_FALSE,
+                                    _("Network interaction failed"),
                                     _("Your password was rejected.") );
                     return -1;
             }
             break;
         default:
             msg_Err( p_access, "user rejected" );
-            intf_UserFatal( p_access, VLC_FALSE, 
-                        _("Network interaction failed"), 
-                        _("Your connection attemp to the server was rejected.") );
+            intf_UserFatal( p_access, VLC_FALSE,
+                        _("Network interaction failed"),
+                        _("Your connection attempt to the server was rejected.") );
             return -1;
     }
 
@@ -361,7 +364,7 @@ static int OutOpen( vlc_object_t *p_this )
     /* Init p_access */
     p_sys->fd_data = -1;
 
-    if( parseURL( &p_sys->url, p_access->psz_name ) )
+    if( parseURL( &p_sys->url, p_access->psz_path ) )
         goto exit_error;
 
     if( Connect( p_this, p_sys ) )
@@ -377,6 +380,7 @@ static int OutOpen( vlc_object_t *p_this )
 
     p_access->pf_seek = OutSeek;
     p_access->pf_write = Write;
+    p_access->p_sys = (void *)p_sys;
 
     return VLC_SUCCESS;
 
@@ -457,7 +461,7 @@ static int OutSeek( sout_access_out_t *p_access, off_t i_pos )
 /*****************************************************************************
  * 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;
     int i_read;
@@ -481,7 +485,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
 /*****************************************************************************
  * Write:
  *****************************************************************************/
-static int Write( sout_access_out_t *p_access, block_t *p_buffer )
+static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
 {
     access_sys_t *p_sys = GET_OUT_SYS(p_access);
     size_t i_write = 0;
@@ -553,6 +557,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:
@@ -608,7 +613,6 @@ static int ftp_ReadCommand( vlc_object_t *p_access, access_sys_t *p_sys,
     int          i_answer;
 
     psz_line = net_Gets( p_access, p_sys->fd_cmd, NULL );
-    msg_Dbg( p_access, "answer=%s", psz_line );
     if( psz_line == NULL || strlen( psz_line ) < 3 )
     {
         msg_Err( p_access, "cannot get answer" );
@@ -617,6 +621,7 @@ static int ftp_ReadCommand( vlc_object_t *p_access, access_sys_t *p_sys,
         if( ppsz_answer ) *ppsz_answer  = NULL;
         return -1;
     }
+    msg_Dbg( p_access, "answer=%s", psz_line );
 
     if( psz_line[3] == '-' )    /* Multiple response */
     {
@@ -680,7 +685,7 @@ static int ftp_StartStream( vlc_object_t *p_access, access_sys_t *p_sys,
         return VLC_EGENERIC;
     }
 
-    if( psz_ip != NULL )
+    if( *psz_ip )
     {
         char psz_fmt[7] = "(|||%u";
         psz_fmt[1] = psz_fmt[2] = psz_fmt[3] = psz_parser[1];
@@ -694,7 +699,7 @@ static int ftp_StartStream( vlc_object_t *p_access, access_sys_t *p_sys,
     }
     else
     {
-        unsigned  a1, a2, a3, a4, p1, p2;
+        unsigned a1, a2, a3, a4, p1, p2;
 
         if( ( sscanf( psz_parser, "(%u,%u,%u,%u,%u,%u", &a1, &a2, &a3, &a4,
                       &p1, &p2 ) < 6 ) || ( a1 > 255 ) || ( a2 > 255 )
@@ -747,9 +752,13 @@ static int ftp_StartStream( vlc_object_t *p_access, access_sys_t *p_sys,
                          p_sys->url.psz_path ) < 0 ||
         ftp_ReadCommand( p_access, p_sys, &i_answer, NULL ) > 2 )
     {
-        msg_Err( p_access, "cannot retreive file" );
+        msg_Err( p_access, "cannot retrieve file" );
         return VLC_EGENERIC;
     }
+
+    shutdown( p_sys->fd_data,
+              ( p_access->i_object_type == VLC_OBJECT_ACCESS ) );
+
     return VLC_SUCCESS;
 }