]> git.sesse.net Git - vlc/blobdiff - modules/access/ftp.c
Export Content-Type out of HTTP access using Control.
[vlc] / modules / access / ftp.c
index cd00bb8331f5ca98f6ac9f25c2a98979d6044ca5..b44368435bfe636bed7fcc3403dd6d84b549628f 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
@@ -86,7 +86,6 @@ 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();
 
@@ -127,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;
     }
@@ -137,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;
     }
@@ -197,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;
                     }
@@ -207,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;
     }
 
@@ -365,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 ) )
@@ -381,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;
 
@@ -557,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:
@@ -612,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" );
@@ -621,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 */
     {
@@ -684,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];
@@ -698,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 )
@@ -751,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;
 }