[FFmpeg-cvslog] lavf/ftp: make response parsing more RFC compliant

Lukasz Marek git at videolan.org
Fri Jul 4 02:28:35 CEST 2014


ffmpeg | branch: master | Lukasz Marek <lukasz.m.luki2 at gmail.com> | Thu Jul  3 21:08:23 2014 +0200| [3ba6dce48dc1e957dada8bfbff9106a2444e22c4] | committer: Lukasz Marek

lavf/ftp: make response parsing more RFC compliant

Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3ba6dce48dc1e957dada8bfbff9106a2444e22c4
---

 libavformat/ftp.c |   47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/libavformat/ftp.c b/libavformat/ftp.c
index 6001165..e99d4dd 100644
--- a/libavformat/ftp.c
+++ b/libavformat/ftp.c
@@ -119,7 +119,7 @@ static int ftp_get_line(FTPContext *s, char *line, int line_size)
  */
 static int ftp_status(FTPContext *s, char **line, const int response_codes[])
 {
-    int err, i, dash = 0, result = 0, code_found = 0;
+    int err, i, dash = 0, result = 0, code_found = 0, linesize;
     char buf[CONTROL_BUFFER_SIZE];
     AVBPrint line_buffer;
 
@@ -135,25 +135,36 @@ static int ftp_status(FTPContext *s, char **line, const int response_codes[])
 
         av_log(s, AV_LOG_DEBUG, "%s\n", buf);
 
-        if (strlen(buf) < 4)
-            continue;
-
+        linesize = strlen(buf);
         err = 0;
-        for (i = 0; i < 3; ++i) {
-            if (buf[i] < '0' || buf[i] > '9')
-                continue;
-            err *= 10;
-            err += buf[i] - '0';
+        if (linesize >= 3) {
+            for (i = 0; i < 3; ++i) {
+                if (buf[i] < '0' || buf[i] > '9') {
+                    err = 0;
+                    break;
+                }
+                err *= 10;
+                err += buf[i] - '0';
+            }
         }
-        dash = !!(buf[3] == '-');
-
-        for (i = 0; response_codes[i]; ++i) {
-            if (err == response_codes[i]) {
-                if (line)
-                    av_bprintf(&line_buffer, "%s", buf);
-                code_found = 1;
-                result = err;
-                break;
+
+        if (!code_found) {
+            for (i = 0; response_codes[i]; ++i) {
+                if (err == response_codes[i]) {
+                    code_found = 1;
+                    result = err;
+                    break;
+                }
+            }
+        }
+        if (code_found) {
+            if (line)
+                av_bprintf(&line_buffer, "%s\r\n", buf);
+            if (linesize >= 4) {
+                if (!dash && buf[3] == '-')
+                    dash = err;
+                else if (err == dash && buf[3] == ' ')
+                    dash = 0;
             }
         }
     }



More information about the ffmpeg-cvslog mailing list