[vlc-commits] ftp: handle preliminary (1xx) reply systematically
Rémi Denis-Courmont
git at videolan.org
Sun Nov 20 18:31:34 CET 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 20 19:28:21 2016 +0200| [4890a413e8fc0e780149b94ff46a0239094d052b] | committer: Rémi Denis-Courmont
ftp: handle preliminary (1xx) reply systematically
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4890a413e8fc0e780149b94ff46a0239094d052b
---
modules/access/ftp.c | 49 +++++++++++++++++++++++++++++++++++++------------
1 file changed, 37 insertions(+), 12 deletions(-)
diff --git a/modules/access/ftp.c b/modules/access/ftp.c
index e05b702..280a808 100644
--- a/modules/access/ftp.c
+++ b/modules/access/ftp.c
@@ -225,18 +225,13 @@ static char *ftp_GetLine( vlc_object_t *obj, access_sys_t *sys )
These strings are not part of the requests, except in the case \377\377,
where the request contains one \377. */
-static int ftp_RecvAnswer( vlc_object_t *obj, access_sys_t *sys,
- int *restrict codep, char **restrict strp,
- void (*cb)(void *, const char *), void *opaque )
+static int ftp_RecvReply( vlc_object_t *obj, access_sys_t *sys,
+ char **restrict strp,
+ void (*cb)(void *, const char *), void *opaque )
{
- if( codep != NULL )
- *codep = 500;
- if( strp != NULL )
- *strp = NULL;
-
char *resp = ftp_GetLine( obj, sys );
if( resp == NULL )
- goto error;
+ return -1;
char *end;
unsigned code = strtoul( resp, &end, 10 );
@@ -266,18 +261,48 @@ static int ftp_RecvAnswer( vlc_object_t *obj, access_sys_t *sys,
while( !done );
}
- if( codep != NULL )
- *codep = code;
if( strp != NULL )
*strp = resp;
else
free( resp );
- return code / 100;
+ return code;
error:
free( resp );
return -1;
}
+static int ftp_RecvAnswer( vlc_object_t *obj, access_sys_t *sys,
+ int *restrict codep, char **restrict strp,
+ void (*cb)(void *, const char *), void *opaque )
+{
+ char *str;
+ int val = ftp_RecvReply( obj, sys, &str, cb, opaque );
+ if( (val / 100) == 1 )
+ { /* There can be zero or one preliminary reply per command */
+ free( str );
+ val = ftp_RecvReply( obj, sys, &str, cb, opaque );
+ }
+
+ if( val >= 0 )
+ {
+ if( codep != NULL )
+ *codep = val;
+ if( strp != NULL )
+ *strp = str;
+ else
+ free( str );
+ val /= 100;
+ }
+ else
+ {
+ if( codep != NULL )
+ *codep = 500;
+ if( strp != NULL )
+ *strp = NULL;
+ }
+ return val;
+}
+
static void DummyLine( void *data, const char *str )
{
(void) data; (void) str;
More information about the vlc-commits
mailing list